Answer the question
In order to leave comments, you need to log in
Do I need to use keep-alive between reverse proxy (nginx) and backend server?
There is a backend web server with nginx in front of it. Does it make sense to use keep-alive between them? Interested in the answer in terms of performance and resource costs of both servers.
Thoughts:
- With keep-alive enabled, fewer connections should be spawned, especially since many requests from many users should crawl through several persistent connections.
- On the other hand, hanging keep-alive connections consume resources of both the operating system and both web servers.
- Suppose that the backend will give content slowly (I don’t know for what reasons, but suddenly), then the number of keep-alive connections can grow dramatically and remain hanging all the time they exist. Will this lead to some unpleasant effect? It is clear that if there are too many of them, then new connections will not be created, but without keep-alive and with a slow backend, there will also be a lot of them, right? Perhaps you need to use keep-alive with a small timeout (a couple of seconds)?
Answer the question
In order to leave comments, you need to log in
Depends on. If you have a large margin of memory / processor - turn it on (of course, by turning the number of backend workers to the desired number).
If there is not enough memory, then keep-alive will not allow "extra" backend processes (especially if it is apache2) to terminate and release memory. For example, without keep-alive, it is quite possible to respond to yourself quite cheerfully with two or three Apache processes, and with keep-alive enabled, it will probably jump to the maximum of simultaneously running ones.
In general, the operation of establishing a connection over a local loop costs a penny in time, so if you explicitly go to the backend on 127.0. .
Well, yes, do not forget that nginx has supported keep-alive to backends not so long ago, so it is likely that in some Ubuntu lts the current version does not support it at all.
It is better to enable keep-alive with clients if more than one and a half pages go to your site, of course. And nginx spends almost nothing on maintaining such connections - almost all the work in this place is done by the kernel.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question