最佳thread数量

cpu 密集性task,过多的线程反而降低了处理效率,最佳的做法就是保持和cpu core数量大致相同的线程数量:

threads = number of CPUs + 1

io密集型,因为会有cpu idel,增加线程数量,可以提高cpu的利用率。具体算法:

threads = number of cores * (1 + wait time / service time)

参考

http://baddotrobot.com/blog/2013/06/01/optimum-number-of-threads/

http://ifeve.com/how-to-calculate-threadpool-size/

https://justdo2008.iteye.com/blog/2291365

原文地址:https://www.cnblogs.com/zhouj-happy/p/11047796.html