Many threads or as few threads as possible?

前端 未结 5 832
走了就别回头了
走了就别回头了 2020-12-25 08:40

As a side project I\'m currently writing a server for an age-old game I used to play. I\'m trying to make the server as loosely coupled as possible, but I am wondering what

5条回答
  •  情话喂你
    2020-12-25 09:11

    I think the question you should be asking is not if 200 as a general thread number is good or bad, but rather how many of those threads are going to be active.

    If only several of them are active at any given moment, while all the others are sleeping or waiting or whatnot, then you're fine. Sleeping threads, in this context, cost you nothing.

    However if all of those 200 threads are active, you're going to have your CPU wasting so much time doing thread context switches between all those ~200 threads.

提交回复
热议问题