I am writing a server that should serve a large number of clients. I am considering which strategy is best used. I read that a class ThreadPoolin the .NET Framework allocates threads after taking into account parameters such as the number of cores the machine is running on, which is great. However, if there are no threads available, he expects him to become available.
The connections on my sockets can be quite long, i.e. a thread may work for a while before it is executed to serve its client and completed. Therefore, if I start a new thread for each socket, it is theoretically possible that a large number of threads will be inactive (waiting for data in the socket), but it is still considered running and, thus, prevents ThreadPoolthe allocation of new threads and serving other clients. On the other hand, using a predetermined number of threads to serve all sockets does not provide optimal use of several core cores.
I guess there is a better way to do this ... Any suggestions?
Thank.
source
share