How to get rid of TCP or lighttpd 4KB buffering on CGI output

cgilighttpdtcp

I have a stock lighttpd install on a Amazon Linux AMI running on EC2. The only config changes I did is to enable CGI support.

Then there is a custom CGI tool (written in C) put in /cgi-bin/ that is called from the outside world and outputs gzip'ed JSON. This tool outputs data regularly, say every 10-20 seconds, but only a few hundreds bytes each time.

The problem is that somewhere between the CGI stdout and what lighttpd returns to the client, things are buffered and arrive about 4KB at a time. Unfortunately, this system is behind the Amazon Elastic Load Balancer which doesn't allow idle connections for more than 60 seconds. Because of the buffering, it's as-if the server returns nothing the first 60 seconds, so the connection gets killed and the client doesn't get anything.

So how do I track down this buffering setting and reduce it significantly? I tried changing some lighttpd config parameters and even changing "net.ipv4.tcp_wmem" in the kernel, but nothing appears to work.

Best Answer

strace the lighttpd process with follow enabled:

strace -f -tt -p PIDOFLIGHTTPD

You will get output that shows each system call made by lighttpd and the CGI. The microsecond timestamp should indicate when the CGI is returning data and when lighttpd is writing it back to the client. This will also answer if the issue is upstream(if you see lighttpd sending back data almost instantly, etc).

Related Topic