日志系统,如log4j或者glog等等有没有对于日志落到磁盘上的时间有没有什么保证?如何实现日志系统能在1min内将日志写到磁盘上。
PHP中文网2017-04-17 14:34:54
No, in order to improve performance, memory buffering and disk buffering technology must be used.
PHP中文网2017-04-17 14:34:54
If you have requirements on the time it takes to spend on your hard drive, you may need to write it yourself;
Just like the fprintf we usually use for output, for performance reasons, the functions of the runtime library are buffered (the cache is usually around 4K, but not necessarily); buffering can reduce the number of system calls; you may adjust fprintf several times , there will be one write call to actually write to the hard disk;
If you implement it yourself, for real-time considerations, directly use the system call interface write() to record logs;
If there is a buffer tolerance of 1 minute, you can use fprintf when writing logs, but call fflush() once every minute to force the logs to fall to the hard disk;
PS: If there is such a strong flash interface on log4j, you can check the information;