io - Erlang消费者队列

标签 io erlang queue throughput

我有一个问题,我想将离散的数据 block 从磁盘拉入队列,并将它们出列到另一个进程中。该数据随机位于磁盘上,因此不会从顺序读取中获得很大好处。数据量很大,所以我无法一次加载全部数据,一次拉入一个 block 也效率不高。

我希望消费者能够以自己的速度运行,但要为其准备好一个健康的数据队列,这样我在处理 block 时就不会一直等待磁盘读取。

有没有既定的方法可以做到这一点?即工作框架或安全阀?实现这一点感觉就像重新发明轮子,因为对磁盘数据操作缓慢的消费者是一个常见问题。

关于如何最好地以 Erlang 方式解决这个问题,有什么建议吗?

最佳答案

您可以在file:open/2上使用{read_ahead, Bytes}选项:

{read_ahead, Size}

This option activates read data buffering. If read/2 calls are for significantly less than Size bytes, read operations towards the operating system are still performed for blocks of Size bytes. The extra data is buffered and returned in subsequent read/2 calls, giving a performance gain since the number of operating system calls is reduced.

The read_ahead buffer is also highly utilized by the read_line/1 function in raw mode, why this option is recommended (for performance reasons) when accessing raw files using that function.

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

您对提到的使用大小一直含糊其辞,但似乎调整该缓冲区大小应该是实现您所需内容的一个不错的开始。

关于io - Erlang消费者队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31420384/

相关文章:

c# - 来自 System.IO.Compression 和异步 I/O 的 ZipFile 和 ZipArchive 类

sockets - 二郎 get_tcp :recv data length

c - 想弄清楚为什么在我什么都没做的情况下结构元素发生了变化

sql-server - 从 SQL Native 存储过程 (Hekaton) 中的表进行更新

io - 如何将文本写入本地文件

java - 分隔文本文件中的所有单词

Windows 在登录时自动启动时的 C++ 文件权限

list - 如何在 Erlang 中使用闭包?

hash - 在 erlang 中计算 MD5 哈希值

java - 为什么priorityQueue不对元素进行排序