nghttp2 / nghttp2

nghttp2 - HTTP/2 C Library and tools
https://nghttp2.org
Other
4.62k stars 871 forks source link

Slow performance #730

Open domenkozar opened 7 years ago

domenkozar commented 7 years ago

Using nghttp2 1.16.1:

$ \time $(nix-build -A nghttp2)/bin/nghttp https://cache.nixos.org/nar/1wyksagbra4m12z5qka02jnaylc9w93szg36yxm9h4c93bszr0ci.nar.xz > /dev/null
0.13user 0.18system 0:22.37elapsed 1%CPU (0avgtext+0avgdata 6532maxresident)k
0inputs+0outputs (0major+300minor)pagefaults 0swaps

$ \time curl --http2 https://cache.nixos.org/nar/1wyksagbra4m12z5qka02jnaylc9w93szg36yxm9h4c93bszr0ci.nar.xz > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24.7M  100 24.7M    0     0  1143k      0  0:00:22  0:00:22 --:--:-- 1254k
0.16user 0.21system 0:22.18elapsed 1%CPU (0avgtext+0avgdata 6876maxresident)k
0inputs+0outputs (0major+546minor)pagefaults 0swaps

$ \time curl --http1.1 https://cache.nixos.org/nar/1wyksagbra4m12z5qka02jnaylc9w93szg36yxm9h4c93bszr0ci.nar.xz > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24.7M  100 24.7M    0     0  5715k      0  0:00:04  0:00:04 --:--:-- 5866k
0.10user 0.12system 0:04.44elapsed 5%CPU (0avgtext+0avgdata 6992maxresident)k
0inputs+0outputs (0major+543minor)pagefaults 0swaps

This is on Linux. What's the best way to debug further?

domenkozar commented 7 years ago

@tatsuhiro-t

bagder commented 7 years ago

When you discuss pure nghttp2 performance issues you need to use pure nghttp2 and not curl, since curl has its own layers on top that complicates matters. One of curl's long-standing http2 performance issues was recently fixed in this commit: https://github.com/curl/curl/commit/a4d888857ede39a8e2aa5f961048c6362d3a5377

domenkozar commented 7 years ago

The first example uses pure nghttp2 and comparing to second example using curl you can see they yield same timings.

domenkozar commented 7 years ago

Good tip though:

$ \time $(nix-build -A nghttp2)/bin/nghttp -w 30 -W 30 https://cache.nixos.org/nar/1wyksagbra4m12z5qka02jnaylc9w93szg36yxm9h4c93bszr0ci.nar.xz > /dev/null
0.10user 0.11system 0:04.54elapsed 4%CPU (0avgtext+0avgdata 6688maxresident)k
0inputs+0outputs (0major+303minor)pagefaults 0swaps
domenkozar commented 7 years ago

Maybe nghttp2 should change these defaults as well? Or does the RFC specify the default value?

tatsuhiro-t commented 7 years ago

These are default values specified in RFC 7540. The browsers tend to use larger values like 256MiB. Since the goal of nghttp client is debug http2 server, and I don't think it needs to run in optimal speed by effectively disabling flow control. The flow control thing is fragile, and it would be better to turn it on to spot bugs easily. But I agree that this is one of the top question why http2 is slower than http1 in certain cases.