I am curious if someone can give me any ideas or suggestions on how to manage a lot of TCP connections efficiently. I am talking around 1000 tcp connections (maybe more). The application managing all these connections needs to pull information from the client (other end of the connection) periodically. For example, maybe every 30 seconds. I would be using .NET 4.0 for this. Is there anything built in to help with this or a special way to structure everything to manage all these connections without making this application be soo bogged down that it is not useful?
I can give you one quick bit of insight:
Do not even think about spawning a thread per-connection. Use the framework's built-in async/task frameworks instead to manage the connections. That is; let the thread pool do it.
Also, be careful to watch closely what your threads are doing; Be sure you can't ever be reading/writing a connection's stream from multiple threads at once. But at the same time, be careful with how you use locking mechanisms to do so, so you don't end up with a process with 1000 active connections, and a thread pool full of threads waiting to acquire locks that they will never get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With