High Level Rest Client Java initialisation slowing down the application

Using following java code initialising the High Level Rest Client in a web service, without performing any elasticsearch request, I have additional 250ms when calling the web service. commenting this code, I have less avarage 250ms in the timing of request to the web service.
Do you know any reason about this performance ?
Do you recommand to use Elasticsearch Java API Client 8.x for better performance ?
using native HttpsURLConnection give better on whole performance in application but not elasticsearch requests, do you recommand it ?

            KeyStore clientStore = KeyStore.getInstance("PKCS12");
            clientStore.load(new FileInputStream(config.searchKeyStoreFileName), config.searchKeyStorePassword.toCharArray());

            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(clientStore, config.searchKeyStorePassword.toCharArray());

            KeyStore trustStore = KeyStore.getInstance("PKCS12");
            trustStore.load(new FileInputStream(config.searchTrustStoreFileName), config.searchTrustStorePassword.toCharArray());

            TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            tmf.init(trustStore);

            sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            //credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.searchUser, config.searchPassword));
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.searchUser, config.searchPassword));
            RestClientBuilder builder = RestClient.builder(searchServers.get(0), searchServers.get(1));

            builder.setHttpClientConfigCallback(clientBuilder -> {
                clientBuilder.setSSLContext(sslContext);
                clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                return clientBuilder;
            });

            builder.setRequestConfigCallback(requestConfigBuilder -> {
                requestConfigBuilder.setSocketTimeout(1000);
                return requestConfigBuilder;
            });

            restClient = builder.build();

Generally clients are initialised at application startup and then reused throughout the life of the application, allowing long running connections to be used. Setting up connections should therefore not affect request latency.

Thanks ! I missed something in the code and it's fixed.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.