如何增加 I/O 队列深度以最大限度地提高性能
磁盘基准测试通常有一个图表,显示 I/O 吞吐量随着队列深度的增加而增加。我假设硬件级别发生的情况是磁盘控制器正在重新排序请求以与磁头所在的位置一致。但是如何增加我自己的 I/O 密集型应用程序中的队列深度呢?我将使用 C#,但与语言无关的答案可能也会有帮助。
我想到的一种(未经测试的)方法是将磁盘访问拆分为多个文件,并在多个线程中发出 I/O。但肯定有一种方法可以在每个并行 I/O 不使用线程的情况下完成此操作。而且我还假设不需要拆分为多个文件,因为数据库通常是一个文件。
Disk benchmarks typically have a chart that shows the I/O throughput increasing as the queue depth increases. I'm assuming that what's going on at the hardware level is that the disk controller is reordering the requests to coincide with where the magnetic head happens to be. But how can I increase the queue depth in my own I/O-heavy application? I'll be using C#, but language-agnostic answers will probably also be helpful.
One (untested) method that occurred to me was to split my disk access into many files and issue the I/Os in many threads. But surely there is a way to do it without using a thread per parallel I/O. And I'm also assuming that splitting to many files is not needed since a DB is generally one file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要为每个 I/O 操作使用一个线程,但您确实需要并行化您的 I/O。 执行大规模 I/O(如数据库)的服务器通常使用 >I/O 完成端口 (IOCP) 。完成端口允许多个 I/O 请求并行挂起 - 并且可以最大限度地提高底层硬件对排队请求重新排序的能力。当挂起的 I/O 操作完成时,IOCP 使用线程池回调来通知应用程序。
不幸的是,C# 对完成端口的(内置)支持有限 - 但是,有一些 开放-试图弥合这一差距的源库。
请注意,IOCP 不适合心脏脆弱的人 - 并且只有当您真正执行大量 I/O 时才会产生性能优势。
You don't need to use a thread per I/O operation, but you do need to parallelize your I/O. Servers that perform large-scale I/O (like databases) typically use I/O completion ports (IOCP). Completion ports allow multiple I/O requests to be pending in parallel - and can maximize the underlying hardware's ability to reorder queued requests. IOCP use callbacks to a thread-pool to notify an application when pending I/O operations have completed.
Unfortunately, C# has limited (built-in) support for completion ports - however, there are some open-source libraries that attempt to bridge this gap.
Beware, IOCP is not for the weak of heart - and the performance benefit only accrues if you are truly performing a massive amount of I/O.