diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-21 17:40:12 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-21 17:40:12 +0200 |
commit | df28b55c35d8c2f96d4c5077671699d379cb01ff (patch) | |
tree | ba976c2319f7314fa94706c12e34a9268dc28365 /metrics-proxy | |
parent | 83bfc1f7f0469d5d03096a1ca42a697c1e18bf4a (diff) |
Cache the connection target and reuse to avoid ssl renegotiation.
Diffstat (limited to 'metrics-proxy')
-rw-r--r-- | metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/ConfigSentinelClient.java | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/ConfigSentinelClient.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/ConfigSentinelClient.java index d07a52f42bd..9236c68ec87 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/ConfigSentinelClient.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/ConfigSentinelClient.java @@ -24,7 +24,9 @@ import java.util.logging.Logger; public class ConfigSentinelClient extends AbstractComponent { private final static Logger log = Logger.getLogger(ConfigSentinelClient.class.getName()); + private static final Spec SPEC = new Spec("localhost", 19097); private final Supervisor supervisor; + private Target connection = null; @Inject public ConfigSentinelClient() { @@ -33,6 +35,9 @@ public class ConfigSentinelClient extends AbstractComponent { @Override public void deconstruct() { + if (connection != null) { + connection.close(); + } supervisor.transport().shutdown().join(); super.deconstruct(); } @@ -126,7 +131,7 @@ public class ConfigSentinelClient extends AbstractComponent { } for (int i = 1; i < parts.length; i++) { - String keyValue[] = parts[i].split("="); + String [] keyValue = parts[i].split("="); String key = keyValue[0]; String value = keyValue[1]; @@ -155,26 +160,24 @@ public class ConfigSentinelClient extends AbstractComponent { String sentinelLs() { String servicelist = ""; - int rpcPort = 19097; - Spec spec = new Spec("localhost", rpcPort); - Target connection = supervisor.connect(spec); - try { - if (connection.isValid()) { - Request req = new Request("sentinel.ls"); - connection.invokeSync(req, 5.0); - if (req.errorCode() == ErrorCode.NONE && - req.checkReturnTypes("s")) - { - servicelist = req.returnValues().get(0).asString(); - } else { - log.log(Level.WARNING, "Bad answer to RPC request: " + req.errorMessage()); - } + synchronized (this) { + if (connection == null || ! connection.isValid()) { + connection = supervisor.connect(SPEC); + } + } + if (connection.isValid()) { + Request req = new Request("sentinel.ls"); + connection.invokeSync(req, 5.0); + if (req.errorCode() == ErrorCode.NONE && + req.checkReturnTypes("s")) + { + servicelist = req.returnValues().get(0).asString(); } else { - log.log(Level.WARNING, "Could not connect to sentinel at: "+spec); + log.log(Level.WARNING, "Bad answer to RPC request: " + req.errorMessage()); } - return servicelist; - } finally { - connection.close(); + } else { + log.log(Level.WARNING, "Could not connect to sentinel at: " + SPEC); } + return servicelist; } } |