Keep-alive timeout configuration on Orthanc's HttpServer

Hi,

I was debugging an issue with a Boost / Beast http client that would receive end of stream after one request, even with HTTP/1.1 and KeepAlive enabled on client and CivetWeb. Inspecting the response headers of CivetWeb, I noticed something interesting:

Connection: keep-alive
Keep-Alive: timeout=1

The configured Keep-Alive is 1 second, which is a bit short.

I thought to make a quick change in the settings, but it seems this is only configurable at build time:

./OrthancFramework/Resources/CMake/CivetwebConfiguration.cmake: -DCIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS=1

Can I propose a patch to make this configurable and/or up the fixed timeout to something a bit higher? Apache uses 15 seconds, Nginx has 10 as a default.

Regards
Walco

Hi Walco,

Thanks for your suggestion. This has been implemented here.

Best regards,

Alain

That is great. Is that a config setting or just changed to 10 ?

DCIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS=10

I think I have occasionally seen timeouts with my NGINX proxy when using the Stone Viewer. I’ll have to check again, but that might help.

Regarding the Stone Viewer, does that load images in the background or just On Demand ? It seems a bit slower than OHIF and some other viewers.

This is an interesting viewer also: https://volview.netlify.app/

I think they are working on a DicomWeb integration with Orthanc now also.

/sds

Regarding the Stone Viewer, does that load images in the background or just On Demand ? It seems a bit slower than OHIF and some other viewers.

It loads on demand, with some prefetching for the instances that are closed to the one currently displayed. This enormously reduces the network bandwidth.

Hi Alain,

Thanks! That was superfast :slight_smile:

I still would like to contribute in making it configurable - given that Orthanc would usually serve a smaller pool of web and api HTTP clients (or in setups behind a reverse proxy) one might opt to set much higher values; Nginx and Apache default settings are tuned towards serving public web sites with potentially thousands of browser connections.

Regards
Walco

Hi Stephen,

At this moment CIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS is a build time flag, so not configurable at runtime in the configuration.

Regards
Walco

Hi Walco,

I have introduced a new KeepAliveTimeout configuration with a default value of 1 as it was in 1.11.2. I realized that 10 was not ideal at all e.g. when using a web-browser.

HTH,

Alain

Hi Alain,

Great news, to have it configurable!

I’m curious to know how you realized 10 was not a ideal value for web browsers, how did you test this?

Regards
Walco

Hi Walco,

If you set the KeepAliveTimeout to 10 seconds:

When you open the default Orthanc UI in a browser, it loads around 30 files in 30 requests.
If you refresh immediately (within a few seconds), it loads the first 20 files correctly but then, seems to wait for the end of the 10 seconds period to serve the last 10 files.

Note that, by default, there are 50 threads available in Orthanc to server HTTP requests.

So it seems that the HTTP requests are “reserved” for the whole duration of the KeepAliveTimeout period.
Do you think we should investigate that or is this an expected behaviour in HTTP ? disclaimer: I should probably read more about the HTTP protocol !.

Best regards,

Alain