Skip to content

Commit

Permalink
Rejig AHC and Varnish timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
namedgraph committed Nov 30, 2024
1 parent f75e4c9 commit ed9a23d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ services:
- CLIENT_HOST=linkeddatahub
- VARNISH_SIZE=1G
entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|$${BACKEND_HOST}|'"$$BACKEND_HOST"'|g' /etc/varnish/default.vcl && sed -i 's|$${BACKEND_PORT}|'"$$BACKEND_PORT"'|g' /etc/varnish/default.vcl && sed -i 's|$${CLIENT_HOST}|'"$$CLIENT_HOST"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint \"$$0\" \"$$@\""
command: [ "-t", "86400" ] # time to live
command: [ "-t", "86400", "-p", "timeout_idle=60s" ] # time to live
volumes:
- ./platform/varnish-backend.vcl.template:/etc/varnish/default.vcl.template:ro
varnish-end-user:
Expand All @@ -132,7 +132,7 @@ services:
- CLIENT_HOST=linkeddatahub
- VARNISH_SIZE=1G
entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|$${BACKEND_HOST}|'"$$BACKEND_HOST"'|g' /etc/varnish/default.vcl && sed -i 's|$${BACKEND_PORT}|'"$$BACKEND_PORT"'|g' /etc/varnish/default.vcl && sed -i 's|$${CLIENT_HOST}|'"$$CLIENT_HOST"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint \"$$0\" \"$$@\""
command: [ "-t", "86400" ] # time to live
command: [ "-t", "86400", "-p", "timeout_idle=60s" ] # time to live
volumes:
- ./platform/varnish-backend.vcl.template:/etc/varnish/default.vcl.template:ro
email-server:
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/atomgraph/linkeddatahub/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
};
if (maxConnPerRoute != null) conman.setDefaultMaxPerRoute(maxConnPerRoute);
if (maxTotalConn != null) conman.setMaxTotal(maxTotalConn);
//conman.setValidateAfterInactivity(6000); // check connections idle for more than Varnish's idle_timeout which is 5s
conman.setValidateAfterInactivity(30000); // check connections idle for more than Varnish's idle_timeout which is 5s

Integer idleConnTimeout = 4000;
// create monitor thread that evicts idle connections: https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/html/connmgmt.html#d5e418
Expand Down Expand Up @@ -1416,6 +1416,8 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED); // https://stackoverflow.com/questions/42139436/jersey-client-throws-cannot-retry-request-with-a-non-repeatable-request-entity
config.property(ApacheClientProperties.CONNECTION_MANAGER, conman);
config.property(ApacheClientProperties.CONNECTION_CLOSING_STRATEGY, new ApacheConnectionClosingStrategy.GracefulClosingStrategy());

keepAliveStrategy = (HttpResponse response, HttpContext context) -> { return 55000; };
if (keepAliveStrategy != null) config.property(ApacheClientProperties.KEEPALIVE_STRATEGY, keepAliveStrategy);

return ClientBuilder.newBuilder().
Expand Down Expand Up @@ -1480,7 +1482,7 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
};
if (maxConnPerRoute != null) conman.setDefaultMaxPerRoute(maxConnPerRoute);
if (maxTotalConn != null) conman.setMaxTotal(maxTotalConn);
//conman.setValidateAfterInactivity(6000); // check connections idle for more than Varnish's idle_timeout which is 5s
conman.setValidateAfterInactivity(30000); // check connections idle for more than Varnish's idle_timeout which is 5s

Integer idleConnTimeout = 4000;
// create monitor thread that evicts idle connections: https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/html/connmgmt.html#d5e418
Expand Down Expand Up @@ -1510,7 +1512,10 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED); // https://stackoverflow.com/questions/42139436/jersey-client-throws-cannot-retry-request-with-a-non-repeatable-request-entity
config.property(ApacheClientProperties.CONNECTION_MANAGER, conman);
config.property(ApacheClientProperties.CONNECTION_CLOSING_STRATEGY, new ApacheConnectionClosingStrategy.GracefulClosingStrategy());


ConnectionKeepAliveStrategy keepAliveStrategy = (HttpResponse response, HttpContext context) -> { return 55000; };
if (keepAliveStrategy != null) config.property(ApacheClientProperties.KEEPALIVE_STRATEGY, keepAliveStrategy);

return ClientBuilder.newBuilder().
withConfig(config).
sslContext(ctx).
Expand Down

0 comments on commit ed9a23d

Please sign in to comment.