1

I have a website in which Javascript sends HTTP POST Ajax requests every 5 seconds to a PHP script on a CentOS server. If I check netstat, I see lots of connections in TIME_WAIT state (mostly between 6 and 9). And this is for just one user. But the website should be getting hundreds, maybe thousands of such requests every 5 seconds from users viewing the website. The PHP script then gets some data from the DB to return it to the user. So I am wondering if my current solution is good/not resource intensive for the server.

I have looked into changing network settings on the server, such as the usual net.ipv4.tcp_fin_timeout,

net.ipv4.tcp_tw_recycle and

net.ipv4.tcp_tw_reuse.

But the first one is not related to how many TIME_WAIT connections there can be. And I'd rather not change these settings, because it's a web server for the website etc, and not a dedicated server for keepalives only.

I was wondering if Ajax can send HTTP POST using UDP to get rid of the TCP-specific overhead, but that is not possible.

This leads me to the questions: what else can I do to make the sending of keepalives as less resources intensive as possible? Is there a lightweight server service that can handle these kinds of requests?

John
  • 39
  • 3
  • What about using HTML5's websocket feature? This would avoid having to do requests every 5 seconds and the communication would be bi-directionnal too. – Patrick Janser Feb 04 '20 at 14:56
  • I personnaly never used websockets but I must admit that I don't really understand the reason of a keep-alive with Ajax requests every 5 seconds. Can't you change the architecture of the web app to avoid that? If not, why not trying to use NGINX to listen on port 80 and 443 and then call either Node.js to handle the websocket connexions or call PHP FPM to handle the page delivery and Ajax requests? I found this article that could be interesting: https://www.exratione.com/2013/06/websockets-over-ssl-with-nodejs-and-nginx/ To reduce the load of your server, NGINX and Node.js may help. – Patrick Janser Feb 04 '20 at 15:18

0 Answers0