What is the optimal number of threads for performing IO operations in java?

前端 未结 7 1884
陌清茗
陌清茗 2021-01-01 17:54

In Goetz\'s \"Java Concurrency in Practice\", in a footnote on page 101, he writes \"For computational problems like this that do not I/O and access no shared data, Ncpu or

相关标签:
7条回答
  • 2021-01-01 18:25

    Ncpu + expected # of concurrent IO activities is my usual number.

    The key isn't that 20 threads can write a single file to disk faster than 4 threads. If you only have 1 thread per cpu, then while you are writing to disk your process will not be able to use the cpu hosting the thread that is doing the file IO. That CPU is effectively waiting for the file to be written, whereas if you have one more thread it can use the CPU to do real processing in the interim.

    0 讨论(0)
提交回复
热议问题