如何保证我的文件尾随 Linux 缓存中的最新缓冲区
问题是我想保证我的文件拖尾将几乎从不执行磁盘 I/O。
当文件(本质上是日志文件)被java服务器写入磁盘时,我希望它们能够被实时读取并传输到另一个设备。
假设目标设备可以吸收与生成日志文件的源服务器一样多的数据,并且不存在网络饱和或类似问题,那么,如果我总是从文件末尾读取,是否可以保证我读取的数据总是来自Linux的缓冲区缓存?
文件每小时都会滚动一次。
The problem is that I want to guarantee that my file tailing will almost never do disk I/O.
As the files (log files, essentially) are being written to the disk by the java server, I want them to be read and transferred to another device in real-time.
Assuming the target device can suck in as much data as the source server which is generating the log file, and there is no network saturation or similar issues, then, if I am always reading from the end of the file, is it guaranteed that the data I am reading is always from Linux's buffer cache?
Files get rolled over every hour.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保在文件从文件缓存中丢弃之前正在读取该文件。如果您距离文件末尾的位置只有几 MB,我不认为您会遇到问题。
在 Linux 上,在我看来,您可以安全地磁盘缓存总内存的 10% 左右。 (不过我没有证据证明这一点)
You need to ensure you are reading the file before it is discarded from file cache. If you are within a few MB of the where the end of the files is I don't imagine you will have a problem.
On Linux, it appears to me you can safely disk cache about 10% of the total memory. (I have no proof of this however)