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

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

    If the only thing you do with that threads is writing to the disk then your performance increase will be negligible or even harmful as usually drivers are optimized for sequential reads for hard drives so that you're transforming a sequential write in a file to several "random" writes.

    Multithreading can only help you with I/O bound problems if the I/O is perform against different disks, different network cards or different database servers in terms of performance. Nontheless in terms of observed performance the difference can be much greater.

    For example, imagine you're sending several files to a lot of different receivers through a network. You're still network bound so that your maximum speed won't be higher than say 100Mb/S but, if you use 20 threads then the process will be much more fair.

提交回复
热议问题