Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
To close the loop on this: the problem was definitely in lighttpd (maybe because it returns raw CGI output as chunked encoding and needs to buffer for that). I ended up bypassing the problem entirely by changing the CGI tools to work directly with xinetd. So no more lighttpd and no more buffering. –  Pol Aug 21 '11 at 16:36

2 Answers 2

up vote 1 down vote accepted

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).

share|improve this answer

When I used to write cgi's in Perl it was a setting I had to include in the perl script. In perl it was $|=1. You probably need to do the equivalent in C. You might want to ask on Stack Overflow instead.

share|improve this answer
    
What was that setting doing? –  Pol Aug 19 '11 at 23:16
    
Turns on unbuffered mode. –  bahamat Aug 20 '11 at 1:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.