I actually tried the latest 0.6x and .7x. &nbsp;The value of 10 was just for testing and reproducing what I was seeing. &nbsp; I had the system backlog at 1024 so I must have been hitting the 511 of nginx. &nbsp;<div>I verified at least on rel5/centos5 that when the backlog is reached, no RST packet is sent. &nbsp;The SYN is just dropped and ignored. &nbsp;This is also consistent with the documentation of backlog behavior from Stevens, Unix Network Programming.</div>
<div><br></div><div>One of the things that the documentation suggests, but is very vague about, &nbsp;is that the backlog count may not only be connections that are in the SYN_RECV state but also connections that are in the soft ESTABLISHED phase. &nbsp;That is server sent out the syn/ack but has not yet received the ack/first data from the client. &nbsp; I&#39;ll try to verify this.</div>
<div><br></div><div>It would seem that on even a moderately busy server serving pages of images it is very easy to hit the 511 backlog. &nbsp;Even though my server can saturate a gigabit at 16k req/s on ab, i hit this backlog limit pretty regularly on conditions where the average is 200 req/s. &nbsp;&nbsp;</div>
<div>As I explained earlier, when this happens your image is delayed by at least a second until the browser re requests. &nbsp;Worst of all there are no errors, or statistics that would suggest this is happening. &nbsp;Of course I can just increase the backlog but at this point might as well try to understand this mechanism and figure out how to detect it in the future.</div>
<div><br></div><div>I&#39;ll investigate some more and post here in the effort that this may help others with debugging similar issues.</div><div><br></div><div>Radek</div><div>&nbsp;</div><div><div><br><br><div class="gmail_quote">
On Mon, Feb 9, 2009 at 11:02 PM, Igor Sysoev <span dir="ltr">&lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="Wj3C7c">On Mon, Feb 09, 2009 at 01:51:12PM -0800, Radek Burkat wrote:<br>
<br>
&gt; I have been looking at this issue to try to understand the interactions and<br>
&gt; this is what I have found out so far.<br>
&gt; I can reproduce the issue by decreasing the net.ipv4.tcp_max_syn_backlog<br>
&gt; and &nbsp;setting net.ipv4.tcp_syncookies = 0. &nbsp;It makes sense that when the load<br>
&gt; gets a little high the system does not process the accept fast enough and<br>
&gt; the backlog builds up. &nbsp;When the backlog fills up the ACK to the initial SYN<br>
&gt; is not issued.<br>
&gt; It would seem also that enabling syncookies uses some other mechanism as I<br>
&gt; do not see the dropped connections when I have &nbsp;net.ipv4.tcp_syncookies = 1<br>
&gt; and back log to some small value like net.ipv4.tcp_max_syn_backlog =10.<br>
&gt; &nbsp;From what I read so far is that syncookies goes into action when you hit a<br>
&gt; certain high water mark on your backlog buffer. &nbsp;Raising the backlog value<br>
&gt; and/or enabling syncookies seems like a good idea.<br>
&gt; You can look at how many connection are in the backlog with net stat.<br>
&gt; netstat -aln | grep -c SYN_RECV<br>
&gt; 146<br>
&gt; The problem here is that this gives you and instantaneous count of the<br>
&gt; backlog. &nbsp;As you can imagine this backlog is getting filled and cleared at a<br>
&gt; high rate. It would be nice to know when this actually gets full or even<br>
&gt; what the max has been over a period of time. &nbsp;Is there a stat like this in<br>
&gt; net statistics?<br>
&gt; This information seems like it is quite important in determining the<br>
&gt; performance of your server latency.<br>
&gt;<br>
&gt; In nginx there is the optional backlog variable in the listen configuration.<br>
&gt; &nbsp;I imagine that this maps directly to the system call listen. &nbsp;Though I see<br>
&gt; that the nginx backlog default is -1. How does that translate to the system<br>
&gt; parameter which requires an in above 0.<br>
<br>
</div></div>Yes, backlog may affect this. However, it seems that you run very old<br>
nginx as it had been fixed in 2007:<br>
<br>
Changes with nginx 0.6.7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 15 Aug 2007<br>
Changes with nginx 0.5.32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;24 Sep 2007<br>
<br>
 &nbsp; &nbsp;*) Bugfix: now nginx uses default listen backlog value 511 on all<br>
 &nbsp; &nbsp; &nbsp; platforms except FreeBSD.<br>
 &nbsp; &nbsp; &nbsp; Thanks to Jiang Hong.<br>
<br>
Now -1 is used on FreeBSD only and it means the maximum available backlog.<br>
<br>
Besides, net.ipv4.tcp_max_syn_backlog = 10 is too small.<br>
<br>
Also, when kernel has no enough backlog, it usually response with<br>
RST packet, if this is not disabled.<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
&gt; Radek<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Feb 4, 2009 at 12:29 AM, Olivier B. &lt;<a href="mailto:nginx.list@daevel.fr">nginx.list@daevel.fr</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Hello,<br>
&gt; &gt;<br>
&gt; &gt; have you tried to disable syncookies and/or adjust them ?<br>
&gt; &gt; On the varnish documentation (<br>
&gt; &gt; <a href="http://varnish.projects.linpro.no/wiki/Performance" target="_blank">http://varnish.projects.linpro.no/wiki/Performance</a> ) there is at least<br>
&gt; &gt; this setup (in /etc/sysctl.conf) :<br>
&gt; &gt;<br>
&gt; &gt; &nbsp; net.ipv4.tcp_syncookies = 0<br>
&gt; &gt; &nbsp; net.ipv4.tcp_max_orphans = 262144<br>
&gt; &gt; &nbsp; net.ipv4.tcp_max_syn_backlog = 262144<br>
&gt; &gt; &nbsp; net.ipv4.tcp_synack_retries = 2<br>
&gt; &gt; &nbsp; net.ipv4.tcp_syn_retries = 2<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; and what about netfilter connection tracking ?<br>
&gt; &gt;<br>
&gt; &gt; Olivier<br>
&gt; &gt;<br>
&gt; &gt; Radek Burkat a ?crit :<br>
&gt; &gt;<br>
&gt; &gt;&gt; Thanks Igor, for eliminating one variable for me. I noticed that when I<br>
&gt; &gt;&gt; use a single worker and set the affinity to the same core as the ethernet<br>
&gt; &gt;&gt; interface interrupt I decrease the frequency of the issue but do not<br>
&gt; &gt;&gt; eliminate it. &nbsp;Not sure<br>
&gt; &gt;&gt; Are there any kernel/network debugging tools which reach a little deeper<br>
&gt; &gt;&gt; than tcpdump?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Radek<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On Tue, Feb 3, 2009 at 10:11 PM, Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a> &lt;mailto:<br>
&gt; &gt;&gt; <a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt;&gt; wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;On Tue, Feb 03, 2009 at 10:07:27PM -0800, Radek Burkat wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Have a machine running the latest devel version nginx-0.7.33<br>
&gt; &gt;&gt; &nbsp; &nbsp;(tried 0.6.35<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; with same results) for serving small (less than 10K images) and<br>
&gt; &gt;&gt; &nbsp; &nbsp;am seeing on<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; tcpdump that some SYN packets are not responded to right<br>
&gt; &gt;&gt; &nbsp; &nbsp;away.The browser<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; does retransmit these image requests every second and on the 2nd<br>
&gt; &gt;&gt; &nbsp; &nbsp;or 3rd<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; resent SYN, I finally start seeing and ACK, and the images load.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; It is very indeterministic as to when it happens and can only<br>
&gt; &gt;&gt; &nbsp; &nbsp;reproduce it<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; some of the time. &nbsp;When it does occur the outcome is a page with<br>
&gt; &gt;&gt; &nbsp; &nbsp;some images<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; loaded and others (whose SYN packets are not ACKs) are not<br>
&gt; &gt;&gt; &nbsp; &nbsp;loaded.....a few<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; seconds later they load.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Typically the system has ~2000 active connections, most in keep<br>
&gt; &gt;&gt; &nbsp; &nbsp;alive. &nbsp;The<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; load is around 100-200 req/sec.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; I have tries all sorts of settings and configurations suggested<br>
&gt; &gt;&gt; &nbsp; &nbsp;in the<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; maillist but I still dont have the solution for this issue.<br>
&gt; &gt;&gt; &nbsp; &nbsp; from 1 to 4<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; workers, changing the connection counts, different even<br>
&gt; &gt;&gt; &nbsp; &nbsp;handlers, kernel<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; buffers, etc.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; It just seems so anecdotal to just change a bunch of settings<br>
&gt; &gt;&gt; &nbsp; &nbsp;without being<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; able to what is happening internally.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; I&#39;d like to be able to debug a little deeper to find out what is<br>
&gt; &gt;&gt; &nbsp; &nbsp;happening<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; to these packets.<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; How would I go about debugging what is the cause of it. &nbsp;Is it<br>
&gt; &gt;&gt; &nbsp; &nbsp;the interface<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; driver, kernel, or nginx? &nbsp;What kind of tools and debugging<br>
&gt; &gt;&gt; &nbsp; &nbsp;options can I<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; try next?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;nginx has not any relation to TCP handshake (SYN, SYN/ACK, ACK),<br>
&gt; &gt;&gt; &nbsp; &nbsp;this is kernel or driver issue.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Thanks, Radek<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; System Details<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; model name : Intel(R) Xeon(R) CPU X3210 @ 2.13GHz<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Linux n06 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 12:03:43 EST 2008<br>
&gt; &gt;&gt; &nbsp; &nbsp;i686 i686<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; i386 GNU/Linux<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; eth0<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Advertised auto-negotiation: Yes<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Speed: 1000Mb/s<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Duplex: Full<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Port: Twisted Pair<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; PHYAD: 1<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Transceiver: internal<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Auto-negotiation: on<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Supports Wake-on: g<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Wake-on: d<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Current message level: 0x000000ff (255)<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Link detected: yes<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; driver: tg3<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; version: 3.86<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; firmware-version: 5721-v3.61, ASFIPMI v6.21<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; bus-info: 0000:05:00.0<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; avg-cpu: %user %nice %system %iowait %steal %idle<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; 0.10 0.00 0.20 2.43 0.00 97.27<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz<br>
&gt; &gt;&gt; &nbsp; &nbsp;await svctm<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; %util<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; sda 0.00 0.00 27.40 0.00 443.20 0.00 16.18 0.10 3.50 3.32 9.10<br>
&gt; &gt;&gt; &nbsp; &nbsp;&gt; no overruns or errors on interface.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &nbsp; &nbsp;--<br>
&gt; &gt;&gt; &nbsp; &nbsp;Igor Sysoev<br>
&gt; &gt;&gt; &nbsp; &nbsp;<a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a><br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
<br>
</div></div>--<br>
<div><div></div><div class="Wj3C7c">Igor Sysoev<br>
<a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a><br>
<br>
</div></div></blockquote></div><br></div></div>