2

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.

Pol
  • 123
  • 3
  • 1
    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

3 Answers3

1

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.

bahamat
  • 6,263
  • 24
  • 28
1

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

polynomial
  • 4,016
  • 14
  • 24
0

Lighttpd buffers the output by default. You need server.stream-response-body = 1 as discussed here. Official docs are https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails

Matija Nalis
  • 2,478
  • 24
  • 37