NREL / api-umbrella

Open source API management platform
http://apiumbrella.io
MIT License
2.01k stars 325 forks source link

Conection limit per worker #270

Open rogeriollacerda opened 8 years ago

rogeriollacerda commented 8 years ago

Hi Is there any limit in Nginx with fixed numbers of connections per worker? I have umbrella running with 24 workers and my netstat always show 240 (24*10) TCP connections for my backend. This is a problem cause now, with my production access, I have 37000 TIME_WAIT connections.

My backend connections on 9090 TCP port:

netstat -anp | grep 9090 | wc -l 240

My nginx workers (24 cores):

ps -ax | grep nginx 17430 ? Ss 0:00 svlogd -ttt /opt/api-umbrella/var/log/nginx-reloader 17431 ? Ss 0:00 bash /opt/api-umbrella/embedded/apps/core/current/bin/api-umbrella-nginx-reloader 17432 ? Ss 0:01 svlogd -ttt /opt/api-umbrella/var/log/nginx 17433 ? Ss 0:00 nginx: master process nginx -p /opt/api-umbrella/embedded/apps/core/current/ -c /opt/api-umbrella/etc/nginx/router.conf 17486 ? Sl 21:50 nginx: ruxit companion process
17487 ? S 51:21 nginx: worker process
17488 ? S 51:31 nginx: worker process
17489 ? S 51:32 nginx: worker process
17490 ? S 51:24 nginx: worker process
17491 ? S 51:01 nginx: worker process
17492 ? S 51:13 nginx: worker process
17493 ? S 51:47 nginx: worker process
17494 ? S 52:19 nginx: worker process
17495 ? S 51:38 nginx: worker process
17496 ? S 51:44 nginx: worker process
17497 ? S 52:37 nginx: worker process
17498 ? S 51:36 nginx: worker process
17499 ? S 51:56 nginx: worker process
17500 ? S 53:10 nginx: worker process
17501 ? S 53:17 nginx: worker process
17502 ? S 54:30 nginx: worker process
17503 ? S 53:04 nginx: worker process
17504 ? S 52:02 nginx: worker process
17509 ? S 52:47 nginx: worker process
17510 ? S 52:47 nginx: worker process
17511 ? S 53:23 nginx: worker process
17512 ? S 51:53 nginx: worker process
17513 ? S 52:12 nginx: worker process
17517 ? S 52:19 nginx: worker process
48422 pts/2 S+ 0:00 grep --color=auto nginx

GUI commented 8 years ago

Sorry for the delay. If you have 24 workers, then the 240 connections to the backend API likely comes from the default keepalive settings we configure in nginx. By default, each API backend's nginx upstream is defined with a keepalive 10 setting. With 24 workers, this would lead to the 240 persistent connections you're seeing. The number of connections can grow beyond this, the keepalive setting just sets a minimum number of connections to maintain (which can improve performance by saving the cost of opening and closing connections).

I'm not entirely sure I understand the issue, or question, though. Is this number of connections too high, and you're looking to lower it? Or is it too low, and are you looking to raise it? Or is there some other issue?

The number of keepalive connection is theoretically adjustable via a hidden keepalive_connections option on the API backend records. However, we've never exposed this option via the web interface (this option was mainly added for some of our integration tests). So would you like to be able to adjust this keepalive setting? If so, there are some ways you could do that now by manually editing the API backend records in the database (I can explain in more detail, if you're interested). But if this is what you're looking to do, then this would also be something that should be pretty easy to expose in the web admin tool for easier editing.