diff --git a/docker-compose.yml b/docker-compose.yml index 26a5f9a7b..f85708173 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: @@ -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: diff --git a/src/main/java/com/atomgraph/linkeddatahub/Application.java b/src/main/java/com/atomgraph/linkeddatahub/Application.java index bb0063de2..c45546a2f 100644 --- a/src/main/java/com/atomgraph/linkeddatahub/Application.java +++ b/src/main/java/com/atomgraph/linkeddatahub/Application.java @@ -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 @@ -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(). @@ -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 @@ -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).