okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Why are you using not bounded thread pool by default?

Open zagorulkinde opened this issue 8 years ago • 8 comments

https://github.com/square/okhttp/blob/878bde8fd6939b508adeb21e2911e390cfe27326/okhttp/src/main/java/okhttp3/Dispatcher.java#L65

zagorulkinde avatar Mar 27 '18 08:03 zagorulkinde

There are separate tunable limits per client, but also ways to reuse clients that could cause additional connections and threads to be required. So I think any sensible limit applied here would cause issues. However the limits in place should stop a client instance used sensible from creating an unbounded number of threads in practice.

yschimke avatar Mar 27 '18 08:03 yschimke

Exactly. We put controls on how many runnables are executing concurrently.

swankjesse avatar Mar 27 '18 12:03 swankjesse

https://github.com/square/okhttp/blob/878bde8fd6939b508adeb21e2911e390cfe27326/okhttp/src/main/java/okhttp3/Dispatcher.java#L47-L48

Looks like the request cound queued up unlimited and could cause OOM, is there a way to config dispatcher to have a bounded ready queue? Otherwise I have to bound it outside.

mjsaber avatar Jul 20 '18 23:07 mjsaber

If it's a concern you should bound it outside. Otherwise we'd need a mechanism to configure the limits and reject things and very few users benefit from that.

swankjesse avatar Jul 21 '18 00:07 swankjesse

Thanks!

mjsaber avatar Jul 21 '18 00:07 mjsaber

@swankjesse @mjsaber By bounding the queue outside, do you mean doing something like the following? Will there be any performance impact for doing this check for every send request?

private void sendAsync(Request request) throws IOException {
      if ((okHttpClient.dispatcher().queuedCallsCount())>=20000){
                //log here say not sending anymore
                //rate limited
                logger.severe("Dropping the batch due to slower response time from server");
                failureCount.accept(1);
                return;
      }
     okHttpClient.newCall(request).enqueue(new Callback(){...});
}

sahil-here avatar Feb 18 '21 21:02 sahil-here

That looks reasonable!

swankjesse avatar Feb 19 '21 02:02 swankjesse

Me ayudarían a configurar Docker Buildx gracias.sera de gran ayuda

adr31 avatar Feb 19 '21 02:02 adr31