Welcome! Log In Create A New Profile

Advanced

upstream keepalive close connections actively

All files from this thread

File Name File Size   Posted by Date  
upstream.patch 2.3 KB open | download Matthieu Tourne 08/12/2011 Read message
ngx_http_upstream_keepalive.patch 542 bytes open | download Matthieu Tourne 08/12/2011 Read message
upstream.patch 2.6 KB open | download Matthieu Tourne 08/12/2011 Read message
August 02, 2011 10:50PM
Hi,

I use nginx 0.8.54 together with latest keepalive module and ajp module to build proxy for java runtime, and notice when "accept mutax" is on, the number of upstream connections is 10 to 20 times of that when "accept mutax" is off.

The test environment is 2 CPU cores, 4G RAM.

Nginx conf:

worker_processes 2;

http {
upstream java_server {
server 127.0.0.1:8009 srun_id=jvm1;
keepalive 500 single;
}

server {
listen 80 default;
server_name xxx.xxx.xxx

location /index.jsp {
ajp_intercept_errors on;
ajp_hide_header X-Powered-By;
ajp_buffers 16 8k;
ajp_buffer_size 8k;
ajp_read_timeout 30;
ajp_connect_timeout 20;
ajp_pass java_server;
}
}
}

I use ab -c 100 -n 50000 XXXX to simulate visit, and netstat -an | grep 8009 -c to see how many connections to upstream is built.

when "accept mutax" is on, there is 28473 connections to upstream, but only 1674 connections when "accept mutax" is off.

If there is only on work process, the result is similar to "accept mutax" is off.

Captures packets:

When "accept mutax" is off, It is clear that it is upstream server who closes the connection:
2169 0.215060 127.0.0.1 127.0.0.1 TCP 41621 > 8009 [ACK] Seq=1333 Ack=4654 Win=42496 Len=0 TSV=1513155905 TSER=1513155905
12474 15.216063 127.0.0.1 127.0.0.1 TCP 8009 > 41621 [FIN, ACK] Seq=4654 Ack=1333 Win=42496 Len=0 TSV=1513159655 TSER=1513155905
12499 15.223667 127.0.0.1 127.0.0.1 TCP 41621 > 8009 [FIN, ACK] Seq=1333 Ack=4655 Win=42496 Len=0 TSV=1513159657 TSER=1513159655
12500 15.223672 127.0.0.1 127.0.0.1 TCP 8009 > 41621 [ACK] Seq=4655 Ack=1334 Win=42496 Len=0 TSV=1513159657 TSER=1513159657

When "accept mutax" is on, it comes to nginx:
5966 1.479476 127.0.0.1 127.0.0.1 TCP 54788 > 8009 [ACK] Seq=297 Ack=1035 Win=34944 Len=0 TSV=1513225689 TSER=1513225689
6008 1.483907 127.0.0.1 127.0.0.1 TCP 54788 > 8009 [FIN, ACK] Seq=297 Ack=1035 Win=34944 Len=0 TSV=1513225690 TSER=1513225689
6012 1.484331 127.0.0.1 127.0.0.1 TCP 8009 > 54788 [FIN, ACK] Seq=1035 Ack=298 Win=34944 Len=0 TSV=1513225690 TSER=1513225690
6013 1.484342 127.0.0.1 127.0.0.1 TCP 54788 > 8009 [ACK] Seq=298 Ack=1036 Win=34944 Len=0 TSV=1513225690 TSER=1513225690

I fix this by simply adding a test in the ngx_http_upstream_keepalive_close_handler

static void
ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev)
{
ngx_http_upstream_keepalive_srv_conf_t *conf;
ngx_http_upstream_keepalive_cache_t *item;

int n;
u_char buf;
ngx_connection_t *c;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
"keepalive close handler");

c = ev->data;
item = c->data;
conf = item->conf;

if ((n = c->recv(c, &buf, 1)) == 0) {
ngx_queue_remove(&item->queue);
ngx_close_connection(item->connection);
ngx_queue_insert_head(&conf->free, &item->queue);
}
}

However, I never understand why it fires the event handler.

This email (including any attachments) is confidential and may be legally privileged. If you received this email in error, please delete it immediately and do not copy it or use it for any purpose or disclose its contents to any other person. Thank you.

本电邮(包括任何附件)可能含有机密资料并受法律保护。如您不是正确的收件人,请您立即删除本邮件。请不要将本电邮进行复制并用作任何其他用途、或透露本邮件之内容。谢谢。
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

upstream keepalive - call for testing

Maxim Dounin August 01, 2011 12:10PM

Re: upstream keepalive - call for testing

liseen August 02, 2011 09:38AM

Re: upstream keepalive - call for testing

Maxim Dounin August 02, 2011 01:34PM

Re: upstream keepalive - call for testing

António P. P. Almeida August 02, 2011 11:28AM

Re: upstream keepalive - call for testing

Maxim Dounin August 02, 2011 01:38PM

Re: upstream keepalive - call for testing

David Yu August 02, 2011 01:44PM

Re: upstream keepalive - call for testing

Maxim Dounin August 02, 2011 01:52PM

Re: upstream keepalive - call for testing

David Yu August 02, 2011 01:54PM

Re: upstream keepalive - call for testing

Maxim Dounin August 02, 2011 02:48PM

Re: upstream keepalive - call for testing

David Yu August 02, 2011 03:10PM

Re: upstream keepalive - call for testing

liseen August 02, 2011 11:58PM

Re: upstream keepalive - call for testing

splitice August 03, 2011 01:22AM

Re: upstream keepalive - call for testing

Matthieu Tourne August 03, 2011 08:08PM

Re: upstream keepalive - call for testing

Maxim Dounin August 04, 2011 02:54AM

Re: upstream keepalive - call for testing

splitice August 08, 2011 12:46AM

Re: upstream keepalive - call for testing

Maxim Dounin August 08, 2011 05:24AM

Re: upstream keepalive - call for testing

splitice August 08, 2011 05:36AM

Re: upstream keepalive - call for testing

splitice August 08, 2011 05:38AM

Re: upstream keepalive - call for testing Attachments

Matthieu Tourne August 12, 2011 03:34PM

Re: upstream keepalive - call for testing

Maxim Dounin August 12, 2011 04:00PM

Re: upstream keepalive - call for testing

Matthieu Tourne August 12, 2011 05:14PM

Re: upstream keepalive - call for testing

Maxim Dounin August 12, 2011 06:28PM

Re: upstream keepalive - call for testing Attachments

Matthieu Tourne August 12, 2011 06:44PM

Re: upstream keepalive - call for testing

Matthieu Tourne August 16, 2011 07:32PM

Re: upstream keepalive - call for testing

Maxim Dounin August 16, 2011 08:24PM

Re: upstream keepalive - call for testing

magicbear August 24, 2011 01:11PM

Re: upstream keepalive - call for testing

Maxim Dounin August 24, 2011 08:06PM

Re: upstream keepalive - call for testing

sv August 24, 2011 09:18PM

Re: upstream keepalive - call for testing

magicbear August 25, 2011 01:30AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 03:08AM

Re: upstream keepalive - call for testing

Maxim Dounin August 26, 2011 05:40AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 07:01AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 07:04AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 07:28AM

Re: upstream keepalive - call for testing

Maxim Dounin August 26, 2011 07:38AM

upstream keepalive close connections actively

cfsego August 02, 2011 10:50PM

Re: upstream keepalive close connections actively

Maxim Dounin August 03, 2011 03:40AM

RE: upstream keepalive close connections actively

Charles Chen August 03, 2011 05:54AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 07:54AM

Re: upstream keepalive - call for testing

Maxim Dounin August 26, 2011 11:56AM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 12:17PM

Re: upstream keepalive - call for testing

Maxim Dounin August 26, 2011 02:08PM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 03:00PM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 12:28PM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 01:00PM

Re: upstream keepalive - call for testing

magicbear August 26, 2011 01:51PM

Re: upstream keepalive - call for testing

magicbear August 28, 2011 01:07PM

Re: upstream keepalive - call for testing

magicbear August 28, 2011 01:10PM

Re: upstream keepalive - call for testing

Maxim Dounin August 28, 2011 09:48PM

Re: upstream keepalive - call for testing

magicbear August 31, 2011 04:04PM

Re: upstream keepalive - call for testing

splitice August 31, 2011 09:58PM

Re: upstream keepalive - call for testing

magicbear September 01, 2011 09:38AM

Re: upstream keepalive - call for testing

magicbear September 04, 2011 01:33PM

Re: upstream keepalive - call for testing

Maxim Dounin September 04, 2011 02:22PM

Re: upstream keepalive - call for testing

magicbear September 04, 2011 02:34PM

Re: upstream keepalive - call for testing

Maxim Dounin September 05, 2011 03:10AM

Re: upstream keepalive - call for testing

ビリビリⅤ September 05, 2011 11:44AM

Re: upstream keepalive - call for testing

Maxim Dounin September 05, 2011 02:04PM

Re: upstream keepalive - call for testing

magicbear September 06, 2011 02:39AM

Re: upstream keepalive - call for testing

Matthieu Tourne September 07, 2011 07:36PM

Re: upstream keepalive - call for testing

Maxim Dounin September 08, 2011 05:28AM

Re: upstream keepalive - call for testing

Maxim Dounin September 08, 2011 11:44AM

Re: upstream keepalive - call for testing

Matthieu Tourne September 08, 2011 06:06PM

Re: upstream keepalive - call for testing

magicbear September 14, 2011 06:54PM

Re: upstream keepalive - call for testing

magicbear September 15, 2011 01:52PM

Re: upstream keepalive - call for testing

splitice September 15, 2011 09:44PM

Re: upstream keepalive - call for testing

philipp December 29, 2011 07:47AM

Re: upstream keepalive - call for testing

Maxim Dounin December 29, 2011 10:06AM

Re: upstream keepalive - call for testing

alexscott March 08, 2012 09:30AM

Re: upstream keepalive - call for testing

Andrew Alexeev March 09, 2012 01:20AM

Re: upstream keepalive - call for testing

alexscott March 12, 2012 10:35AM

Re: upstream keepalive - call for testing

Maxim Dounin March 12, 2012 10:56AM

Re: upstream keepalive - call for testing

alexscott March 12, 2012 01:40PM

Re: upstream keepalive - call for testing

alexscott March 12, 2012 03:55PM

Re: upstream keepalive - call for testing

Maxim Dounin March 12, 2012 02:00PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready