gigi81 / sharpfastcgi

C# fastcgi protocol implementation plus shome usage examples. A good example on how to self-host your web application without the need of iis or mono.
MIT License
32 stars 15 forks source link

sockets stuck at CLOSE_WAIT under heavy loads #7

Closed NickTullos closed 9 years ago

NickTullos commented 9 years ago

It seems under heavy loads there is usually 1 or 2 client sockets that do not get closed. After many heavy loads they start adding up. They will sit in CLOSE_WAIT status forever. I creating the load using

ab -n 2000 -c 500 http://127.0.0.1/version/return/string/b

Once I get more details I'll post them here.

I'm using FastCgi.Test app / simple server for my test that returns a string "S" to the client.

gigi81 commented 9 years ago

Hi. I had some tests myself with this command under windows 7. I actually added a bat file in the repository with this command, I don't have this CLOSE_WAIT issue so it would help to understand a little bit more about your setup.

Trying to replicate the issue, I had instead a problem with the TIME_WAIT status. I found out this is by tcp/ip design and there is no real workaround for that. For more details see here: http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for-protocols-and-scalable-servers.html

The best solution I could find was actually to implement the fastcgi side of a nginx feature called "fastcgi_keep_conn".

I added a command line "-k" option to enable this feature as well as the latest version of nginx and configuration using this option. Enabling this option let nginx reuse the same connection for subsequent request, drastically reducing the number of sockets needed.

This actually solves the TIME_WAIT problem and I think it will help with your issue as well. Let me know if you can had some more tests and how it goes. Again please specify details about your setup.

NickTullos commented 9 years ago

I will try the options you posted above and post more feedback if it does not solve the issue. I have a feeling the -k option will solve it. Thank you for your help.. again!