开发者

Would multiple threads speed up code reading from disk into memory?

If I had code which were to read every word of a file into an ArrayList or HashSet, would it be any faster to split the code into multiple worker threads and assign each a chunk of the file to work on (assuming multiple cores)? My gut says no since the I/O would usually be the bottleneck rather than the CPU 开发者_如何学JAVAin a case like this.


The IO channel off a regular drive is usually much faster than what the physical media itself can provide, so IO won't be the bottleneck. With magnetic media (aka a standard harddrive), you'd make the disk thrash like crazy as the heads seek to the various places you're reading from. Performance would be abysmal, the equivalent of a shopping cart rolling down an empty 6lane freeway.

Solid state drives don't suffer from the seek penalty, but they're not widespread (or affordable) enough yet to count for much yet.


It depends. Your line of thinking that the IO is going to be the bottleneck could be correct since a lot of disks work in a serial fashion. But, what if that disk were special like an SSD or a RAID that really did support concurrent access? Also, if there were a significant amount of CPU bound post processing that needs to be done with the data then you could get that going concurrently while another batch of data is being read. Do not write off the concurrent options so quickly!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜