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/