将 open(Filename, {delayed_write, Size, Delay}) 与索引结合起来

发布于 2024-10-01 20:49:32 字数 200 浏览 2 评论 0原文

如何将 open(Filename, {delayed_write, Size, Delay}) 与该数据写入位置的索引结合起来?

我想等到收到一定量的数据,然后将其写入文件中的某个位置。

{read_ahead, Size} 是否与 {delayed_write, Size, Delay} 相反?我想读取一定量的数据来发送它。

谢谢

How can I combine a open(Filename, {delayed_write, Size, Delay}) with an index on where to write this data to?

I want to wait until I receive a certain amount of data and then write it to a position in the file.

Also is {read_ahead, Size} the opposite of {delayed_write, Size, Delay}? I would like to read a certain amount of data to send it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-10-08 20:49:32

read_ahead 与delayed_write 相反,因为读取与写入相反。

如果您想读取并发送更大的内存块,则不需要 read_ahead,只需读取大块并发送它们(此处保存的操作系统调用不多)。

来自 read_ahead 上的 file:open/2 联机帮助页:

如果 read/2 调用的大小不显着小于或什至大于 Size
字节,预计不会有任何性能提升。

打开时不需要指定和索引。只需使用 pwrite/3position/2write/2

但是在文件的不同位置写入可能只会减少 delayed_write 的增益,因为(也是 文件:open/2):

缓冲的
数据也会在其他文件之前刷新
执行 write/2 以外的操作。

如果您有多个位置的大量数据,请将它们收集在 {Location, Bytes} 列表中,并时不时用 file:pwrite/2 一口气完成。这可以映射到非常高效的 writev(2) 系统调用,一次性写入多个块。

read_ahead is kind of the opposite of delayed_write in the sense that reading is the opposite of writing.

If you want to read and send bigger chunks of memory you don't need read_ahead, just read big chunks and send them (not many os calls to save here).

From the file:open/2 manpage on read_ahead:

If read/2 calls are for sizes not significantly less than, or even greater than Size
bytes, no performance gain can be expected.

You don't need to specify and index when opening. Just use pwrite/3 or a combination of position/2 and write/2.

But writing in different positions of the file might just reduce the gain of delayed_write since (also manpage of file:open/2):

The buffered
data is also flushed before some other file
operation than write/2 is executed.

If you have chunks of data for several positions collect them in a list of {Location, Bytes} and from time to time write them with file:pwrite/2 all in one go. This can map to very efficient writev(2) system call that writes several chunks in one go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文