Title
#dev
Ariel Shaqed (Scolnicov)

Ariel Shaqed (Scolnicov)

08/25/2022, 1:44 PM
This blogpost makes me suspect that the generated Java API client does not reuse HTTP connections: we probably get a new SSL Socket Factory each time we create an API client, which prevents reuse.
1:44 PM
Relevant scary lines in ApiClient.java:
SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, new SecureRandom());
            httpClient = httpClient.newBuilder()
                            .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0])
                            .hostnameVerifier(hostnameVerifier)
                            .build();
1:48 PM
I see this:
OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.addNetworkInterceptor(getProgressInterceptor());
This adds a different progress interceptor to each ApiClient, so it seems very likely that OkHttp will generate a different HTTP client each time. And that means we won't re-use connections.
1:52 PM
... and OkHttpClient.kt says:
* ## OkHttpClients Should Be Shared
 *
 * OkHttp performs best when you create a single `OkHttpClient` instance and reuse it for all of
 * your HTTP calls. This is because each client holds its own connection pool and thread pools.
 * Reusing connections and threads reduces latency and saves memory. Conversely, creating a client
 * for each request wastes resources on idle pools.
 *
 * Use `new OkHttpClient()` to create a shared instance with the default settings:
2:14 PM
So https://github.com/treeverse/lakeFS/issues/3995, and verify we do the same in LakeFSFS I guess.