1

I have a server that handle both http and https request.

The common routine between client and server is based on two request:

1) The user request a file with an url, eg.:

https://example.com/get?id=10

2) The server makes some check and redirect in the response headers to a new url:

location: https://example.com/files/10.zip

3) The browser, after redirect to the new url, request the file:

https://example.com/files/10.zip

4) The server, sends the file "10.zip" in the response stream:

ResponseInfo.ContentStream := TFileStream.Create('C:\10.zip', fmOpenRead or fmShareDenyNone);

all routine is of two request (1, 4), and for this reason i have disabled session and keepAlive:

IdHTTPServer.KeepAlive        := False;
IdHTTPServer.AutoStartSession := False;
IdHTTPServer.SessionState     := False;

I think keep alive has huge benefit only on multiple round trip, this seem a good idea into my scenario when user use http, but, maybe this isn't a good idea when the user use https, because each request without KeepAlive is a new request and the initial setup costs of a HTTPS connection are far higher.

Enabling KeepAlive on IdHTTPServer has some performance benefit into my scenario?

Apache 2.4 has default KeepAliveTimeout at 5 seconds. For IndyServer is good a value in order of some seconds?

ar099968
  • 6,963
  • 12
  • 64
  • 127
  • Remove that redirect and you're on single request/response. – Victoria Oct 09 '17 at 15:44
  • @Victoria i want understand if KeepAlive has a performance benefit on >1 requests. – ar099968 Oct 09 '17 at 15:56
  • 1
    I see. Maybe you may take a look at [this thread](https://stackoverflow.com/q/3441075/8041231). It's quite broad to give an ultimate answer to this. If the browser were sending multiple consequent requests in a few seconds, keeping the connection alive makes sense. If e.g. in minutes or hours, it makes no sense to keep it alive. – Victoria Oct 09 '17 at 15:58
  • @ar099968 if you want to see whether KeepAlive has performance benefits, profile the code and see for yourself (hint: it does, especially for HTTPS. You have more round trips than you think) – Remy Lebeau Oct 09 '17 at 16:03
  • @Remy, does Indy server have any kind of keep alive timeout implemented (when any of the sides stops communication for a certain time), not affected by the heartbeat? – Victoria Oct 09 '17 at 16:17
  • @Victoria maybe i'm wrong, but indy seems without timeout, i have set a timeout for close zombie connection `AContext.Connection.Socket.ReadTimeout := 300000;` – ar099968 Oct 09 '17 at 16:19
  • 1
    @Victoria not at this time. It is on my TODO list. However, you can set the `ReadTimeout` for a connection, and if a client doesn't send a new request before that timeout elapses, an exception will be raised to close the connection – Remy Lebeau Oct 09 '17 at 16:21
  • ar099968, because such timeout might be optimal for your task. You'd keep the connection alive and after some time of inactivity, you'd close it (as you say, a _zombie_ connection). That combines the advantage of keeping the connection alive for multiple consequent requests in a _short_ period of time. @Remy, thank you for the info. – Victoria Oct 09 '17 at 17:24
  • @RemyLebeau Apache 2.4 has default KeepAliveTimeout at 5 seconds. For IndyServer is good a value in order of some seconds? – ar099968 Oct 10 '17 at 06:59

0 Answers0