I am trying to figure out exactly how to configure nginx and tomcat to work together correctly.
Nginx has a worker connections
setting and tomcat has max threads
(assuming native apr connector for tomcat). Since nginx is connecting with HTTP/1.0 to backend, keepalive is not needed for tomcat.
I set keep-alive timeout
to 30s in nginx. If 100 req/s is the target and each request finishes in 1s, there can be 100 requests * 30 seconds each = 3000 concurrent connections that can be opened to nginx and there will be 100 concurrent connections to tomcat.
So if I set worker connections
to 6000 in nginx (worker process is 1, and nginx consumes 2 connection per request I think. One for client and one for backend) and max threads
to 100 in tomcat (which is already 200 by default), this will work.
Is there any conceptual problem in this calculation? The exact numbers do not matter.
Thanks.
There are two points you should consider in working out the above calculations:
Otherwise it looks pretty sound.
While forwarding requests from nginx to tomcat: please remember:
you need to set protocol http/1.1 & set connection to "" to enable connection persistence
regards vj