Ariel Shaqed (Scolnicov)

    Ariel Shaqed (Scolnicov)

    1 month ago
    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.
    Relevant scary lines in
    SSLContext sslContext = SSLContext.getInstance("TLS");
                sslContext.init(keyManagers, trustManagers, new SecureRandom());
                httpClient = httpClient.newBuilder()
                                .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustManagers[0])
    I see this:
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    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.
    ... 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:
    So, and verify we do the same in LakeFSFS I guess.