Haproxy - timeout http-request vs timeout http-keep-alive vs timeout server
I'm trying to wrap my head around how the haproxy options
timeout http-request <timeout>
timeout http-keep-alive <timeout>
timeout server <timeout>
interact with each other. I'm running an Apache website on two app servers living behind a haproxy load balancer. Right now I don't have keep-alive enabled, but I've been experimenting with enabling it because I think it would help optimize the site. My goal was to enable keep-alive for connection between the browser and haproxy, but disable keep-alive between haproxy and apache. I accomplished this with
option http-server-close
Now I'm looking into setting up the keep-alive timeouts. I've been studying the haproxy manual for the timeout http-request option, timeout http-keep-alive option, and timeout server option. If I'm understanding the manual correctly, timeout http-keep-alive is the time to keep the connection open between new requests and timeout http-request is the time to wait for the response's headers before closing the connection. But what I can't seem to figure out is what timeout server dictates. I want to say that timeout server is the time to wait for the full response, but can anyone confirm that? If I'm right that timeout server is the time to wait for the full response, then am I correct that it shouldn't have any bearing on the keep-alive timeout settings?
Here's my haproxy config that I'm working on modifying:
global
maxconn 4096
pidfile /var/run/haproxy.pid
daemon
defaults
mode http
retries 3
option redispatch
maxconn 5000
timeout connect 5000
timeout client 300000
timeout server 300000
listen HTTP *:80
mode http
cookie HTTP insert nocache
balance roundrobin
#option httpclose # I just commented this out in favor of http-server-close
option http-server-close
timeout http-keep-alive 500 # from the haproxy manual suggestion of "tens to hundreds of ms"
timeout http-request 5000
option forwardfor
stats enable
stats uri /my-lb-status
stats auth myLbStatus:123456
reqadd X-Forwarded-Proto:\ http
option httpchk GET /robots.txt HTTP/1.0
server SERVER_A 1.2.3.4:80 cookie app_01 check
server maintenance 127.0.0.1:8080 backup
Ultimately my goal is to be able to turn on keep-alive between the browser and haproxy with the requirement of being able to run a report that can take 2-3 minutes to run on the app servers.
Solution 1:
Just to clarify a bit. I hope this also answers your questions.
timeout http-request
Is the time from the first client byte received, until last byte sent to the client (regardless of keep alive). So if your backend is too slow or the client is sending his request too slow, the whole communication might take longer than this, and the request is dropped (and a timeout sent to the client).
timeout http-keep-alive
The time to keep a connection open between haproxy and the client (after the client response is sent out). This has nothing to do with the backend response time. This has nothing to do with the length of a single request (i.e. http-request timeout). This allows faster responses if the user requests multiple ressources (i.e. html, img, and js). With keep alive the single requests can make use of the same tcp connection. This way the load time for a full webpage is reduced.
timeout server
This is the timeout for your backend servers. When reached, haproxy replies with 504 (gateway timeout). This also has nothing to do with keep alive, as it is only about the connection between proxy and backend.