title: Okhttpclient connection pool size dilemma
body: <p>I'm currently using okhttp 3.10.0 and i just recently found out that creating a new client for every new request is bad for to each client having it's own connection pool.</p>
  
  <p>I'm using okhttp inside servlets. Whatever I'm now doing is declaring a static client in each servlet and initializing it inside the init() method</p>
  
  <pre><code>client = new OkHttpClient.Builder()
                .readTimeout(15000,TimeUnit.MILLISECONDS)
                .retryOnConnectionFailure(false)
                .connectTimeOut(10000,TimeUnit.MILLISECONDS)
                .connectionPool(new ConnectionPool(20,5L,TimeUnit.MINUTES)
                .build();
  </code></pre>
  
  <p>Now here, there's the configuration for max idle connections which I'm setting to 20 and the idle timeout is set to 5 minutes.</p>
  
  <p>1) What is the actual pool size, i.e the maximum connections that the pool will have (looking through the code, i found that it might be Integer.MAX_VALUE and max simultaneous connections to a host is default 64 but I'm not sure)?</p>
  
  <p>2) Is this approach good enough. My current approach will be making one client per servlet. So should i instead have one singleton class which gives the same client to all my Servlets in which case what should i configure for ideal load for the following specs.i couldn't find how to configure the actual pool size so i don't know if this even is possible</p>
  
  <p>Digital ocean droplet</p>
  
  <p>Ram 2gb</p>
  
  <p>Cpu cores 2</p>
  
  <p>Tomcat max heap 768mb</p>
  
  <p>Nginx concurrent workers 1000</p>
  
  <p>Mysql max ram ~800mb</p>
  
  <p>Load i'd want to support ~500 users per sec max</p>