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

前端 未结 7 1919
陌清茗
陌清茗 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:03

    If you are using synchronous I/O, then you should have one thread for every simultaneous I/O request your machine can handle. In the case of a single spindle single hard disk, that's 1 (you can either read or write but not both simultaneuosly). For a disk that can handle many I/O requests simultaneously, that would be however many requests it can handle simultaneously.

    In other words, this is not bounded by the CPU count, as I/O does not really hit the CPU beyond submitting requests and waiting. See here for a better explanation.

    There's a whole other can of worms with how many I/O requests you should have in flight at any given time.

提交回复
热议问题