是否有一种 posix 方式来确保两个文件按顺序刷新而不会阻塞?
在我的程序中,我打开两个文件以进行写入,一个是内容文件,包含数据块,另一个是索引文件,包含一个映射,到目前为止已经在该映射上写入了数据块。
我想将它们都刷新到光盘上,尽可能提高性能,唯一的限制是数据文件中的块必须在映射文件中的相应块之前写入(自然地)。
问题是我想避免阻止 IE 执行 fsync,无论是出于延迟还是吞吐量的原因。
有什么想法吗?
In my program, I hold two files open for writing, a content-file, containing chunks of data, and an index-file, containing a map over which chunks of data has been written so far.
I would like to flush them both to disc, as performant as possible, with the only constraint that the blocks in the data-file must be written before the corresponding blocks in the map-file (naturally).
The catch is that I would like to avoid blocking I.E. doing an fsync, both for latency and throughput-reasons.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您无法在单个执行路径中轻松完成此操作。您需要 fsync 来保证写入磁盘 - 这将必须等待写入。
我怀疑通过将写入任务委托给单独的线程或进程来实现这一点是可能的(但并不容易)。在现有程序中生成数据,并使用任何看起来合理的方法将其“写入”第二个线程/进程。这可以是非阻塞的。然后,第二个线程会将任何新数据写入内容文件的数据,然后 fsync,然后写入索引文件,然后再次检查新数据。关键设计决策涉及如何分离两个执行路径、如何在它们之间进行通信以及是否需要将写回报告给主程序。这仍然可能存在延迟和吞吐量问题,但这是选择同步索引文件和内容文件的成本的一部分。至少在等待磁盘时有机会完成工作。
值得一看的是,它是否被很好地封装,以便在任何事务数据库的源中对您有用。您还可以在装载内容文件的文件系统时研究同步选项。
I don't think you can do this easily in a single execution path. You need fsync to have the write to disk guaranteed - and this is going to have to wait for the write.
I suspect it is possible (but not easy) to do this by delegating the writing task to a separate thread or process. Generate the data in your existing program and 'write' it to the second thread/process using any method that looks sensible. This can be non-blocking. The second thread would then write any new data to the data to your content-file, then fsync, then write the index-file, then check for new data again. Key design decisions relate to how you separate the two execution paths, how you communicate between them, and if you need to report the write back to the main program. This could still have latency and throughput issues, but that's part of the cost of choosing to have the index-file and content-file in sync. At least there would be a chance of getting work done while waiting on the disk.
It could be worth looking to see if this is well encapsulated so as to be useful to you in the source of any of the transactional databases. You could also investigate the sync option when you mount the file system for the content-file.