1

Suppose I have to read, process and update a lot of files in Java. I am going to use one computer with 16 cores. Since I have both IO-bound (read and update files) and CPU-bound (processing) tasks I allocate 2 thread pools.

I would allocate one pool for CPU-bound tasks with 16 threads (the number of threads == the number of CPUs). Now I wonder what the IO-bound pool size is. Thread pools of what sizes would you suggest ?

Michael
  • 41,026
  • 70
  • 193
  • 341
  • 3
    I would suggest testing. Can't beat actual results you know. – Kayaman Oct 15 '13 at 07:46
  • 1
    I'd say the number of processing cores available... – Thihara Oct 15 '13 at 07:48
  • I would suggest to leave at least 1 CPU for the operating system, then do testing with available tools to check where the bottle-neck in an real-world aproximation – RamonBoza Oct 15 '13 at 07:49
  • I never would count on Java about management of threads, for low-level management, you may need to switch to something more reliable, like pthread. –  Oct 15 '13 at 11:55

1 Answers1

4

It would depend on your storage capabilities and what kinds of IO you are trying to do. For example, long sequential writes on harddisks would favor a single IO thread, but you would want to scale this according to your requirements.

In this answer, https://stackoverflow.com/a/2821025/2855891, BlackAura explains why experimentation and profiling is probably the only way you can really find out.

There are probably already very good articles on this topic.

Community
  • 1
  • 1
KnownColor
  • 449
  • 5
  • 12