Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm currently having a socket leak with my Node.js application. This bug is also posted here. I hope to fix this soon. CLOSE_WAIT and FIN_WAIT2 seem to be the major problem.

Connections:    1662
ESTABLISHED:    238
CLOSE_WAIT:     770
FIN_WAIT1:      4
FIN_WAIT2:      632

The following data is retrieved by entering (alternatives like) this:

netstat -anp | grep ${node_pid} | wc -l

I've read that you can solve this by tuning these variables:

net.ipv4.tcp_fin_timeout    ( = 60 )
net.ipv4.tcp_keepalive_time ( = 7200 )

Although my tcp_fin_timeout is set to 60 seconds, my sockets keep being there for more than 60 seconds. That's why I think I should tune the tcp_keepalive_time.

It's hosted on a Linux Centos 5 server which is also running Apache and MySQL.

Can I easily decrease tcp_keepalive_time to something like 1800, or will it have negative impacts on Apache, for example?

share|improve this question

1 Answer 1

There are multiple options you can tune to save on server resources relating to connection. See this page for a couple of of the options and their description. Also, see the list of refernces at the end of that page:

man 7 ip
man 7 tcp
http://www.faqs.org/docs/securing/chap6sec70.html
http://man7.org/linux/man-pages/man7/ip.7.html
http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html 

You can reduce the tcp_fin_timeout to say 20, as this is solving a problem that arises at the end of a connections lifetime/requirement. The same for the tcp_keepalive_time, if you bring it down to a sensible value and not too low (say 600, when used with tcp_keepalive_intvl and tcp_keepalive_probes).

There shouldn't be any negative effects with your Apache server as typical web HTTP traffic is very bursty and short lived. Unless a user is downloading a large file over a link with very high packet loss, in which case, accessing your site would be the least of their worries.

If you just read the man pages and those links it should become pretty (any confusion, post a question here obviously!).

share|improve this answer
    
Thanks a lot! I will see into this later when I have time! –  Martin May 7 '13 at 17:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.