square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Home Page:https://square.github.io/okhttp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Performance problems with Http2

mrozk opened this issue · comments

commented

Hi! Guys, it seems that OkHttpClient has problems with performance on HTTP_2. We are testing HTTP_2 on our microservices. Our client uses Feign and Spring Cloud Loadbalancer under the hood and we added OkHttpClient with HTTP_2 enabled(PRIOR_KNOWLEDGE). Our downstream service is a cluster of 120 pods. We saw that resource consumption was increased several times, especially threads count. We did a thread dump and saw, that OkHttpClient creates a thread per a connection, although OkHttpClient with HTTP_1 doesn't do it.
Screenshot 2022-06-20 at 14 21 45
Screenshot 2022-06-20 at 10 24 02

Did we do something wrong during the OkHttpClient configuration, or is it normal library behavior?

Yes, one thread per connection is expected. Is this causing performance problems beyond the thread use?

commented

Thanks for answering. Actually, 250 running threads instead of 50, is already a performance problem, which causes extra context switching, etc. I believe that switching on http/2 should save resources, not increase its consumption several times.
Actually, we don't have such a situation using http/1 with OkHttp, that's why I'm asking.

Yeah, for HTTP/1 OkHttp doesn’t need a thread to wait on the inbound socket in case a frame arrives. For HTTP/2 we need a thread per socket. It’s usually not a problem because usually the number of HTTP/2 connections isn’t substantial.

One potential fix for this is Project Loom, wherein a waiting thread doesn’t cost many resources.

Closing, as this is intended and not something we can fix until Loom.