Efficient Number of Threads

前端 未结 6 548
小鲜肉
小鲜肉 2020-12-28 10:23

I want to optimize my application number of threads. Almost all of them have IO beside CPU usage in an equal value. How much is the efficient number of threads when there ar

6条回答
  •  鱼传尺愫
    2020-12-28 10:48

    The Java Concurrency in Practice book gives a rough formula for sizing a thread pool to keep your CPUs pegged at a certain utilization:

    N = number of CPUs

    U = target CPU utilization, 0 <= U <= 1

    W / C = ratio of wait time to compute time

    The optimal pool size (number of threads) for keeping processors at the desired utilization is:

    PoolSize = N * U * (1 + (W/C))

    This is just for CPU utilization though.

    You can get the available processors with Runtime.getRuntime().availableProcessors()

提交回复
热议问题