Too Many ESTABLISHED connection from a single IP address in Apache

Solution 1:

tcp_tw_reuse and tcp_tw-recycle and tcp-fin_timeout to 30

The fin timeout helps here but reuse and reccyle? Why?

keepalive timeout 10

This is just silly. Even with dialup, this should be 3 or less.

timeout 300

Do you know what this does? This might be the default but it is way too high again.

You might try capturing some of the traffic using wireshark to see exactly why the connections are not closing.

Is using mod_reqtimeout an option

Only if the client is very badly broken and you're not bothered about providing a service to them.

should we move to ngnix server

It'll certainly handle slow connections much more easily, however you might want to use as a proxy (and you can selectively/transparently route particular subnets via this using iptables)

Solution 2:

The problem is related to low speed clients. Best way to solve this is to use reverse proxy solution e.g. nginx, varnish or similar software if from of your apache. A good reverse proxy server can handle thousands of connections without problems.

Why is setting Nginx as a reverse proxy a good idea?

Solution 3:

Have you tried dropping the Timeout directive to something much lower, such as 10 or 5?

Alternatively, you could try switching away from the prefork MPM (if possible) and use an event-driven model such as the event MPM in Apache 2.4 or a different web server such as nginx.

You could also use nginx (or similar) as a reverse proxy in front of Apache. The proxy will wait until it has received the entire request before making the upstream request to Apache. This request will then have no delays in the middle of it.

The problem with running out of Apache children can also be caused or exacerbated by the Keepalive settings you have. Consider switching that off or lowering the keepalive timeout value. Making it too low may make it useless, of course.