I am building a load generator for a simple Python multi-threaded web server. The load generator takes a user-provided number of threads, starts up a client, connects to server and requests a short file, then disconnects. The server creates a new thread for every new client connection.
What is happening is I am able to instantiate about 100 client threads without any issue. But When I increase it to 1000 or more threads, I get undesirable results. I get the following errors:
- error: [Errno 32] Broken pipe when the client calls
sendall
, - error: [Errno 54] Connection reset by peer when the client calls
recv
.
What is going on and what is the proper way to handle these errors?
Edit
Clearly, I can just catch these socket errors. Is it appropriate to just catch the above errors, or should they be handled? If they should be handled, how should they be handled? These errors are not infrequent or randomly occurring; they occur consistently whenever my load generator spawns > ~100 threads.
I understand now that [Errno 32] Broken pipe occurs when the receiving side of the socket has been closed, and then the write side tries to write to it. In that case, then the receive side (server-side) is closing prematurely, but I'm not sure how to prevent this from happening or if there is even a way.