Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undesired (as in older faster than newer) perf delta between older and newer APIs #756

Open
weissi opened this issue Jul 23, 2024 · 0 comments

Comments

@weissi
Copy link
Contributor

weissi commented Jul 23, 2024

Expected behavior

The newer AHC interfaces should be as fast as the older ones (or faster!). At least if installing NIO as the Concurrency executor (or NIO executor preference) to avoid thread hops.

Actual behavior

Slower. My (silly and not super scientific) benchmark is

  • 100k real but super basic (just GET / response just HTTP/1.1 200 ok\r\n\r\nHello World) HTTP requests to a real server (NIOHTTP1Server) over loopback on macOS (but using MultiThreadedEventLoopGroup.singleton for perf). Thread hop costs should be minimal here because it should be just a single hop onto the I/O and back. And we'll need to wait for the server anyway.

Here are the results:

  • AHC with future-based API: 5.9s
  • AHC with async API and NIO as executor (no hops): 7.1s (+ 1.2 seconds)
  • AHC with async API and default executor (a few hops): 8.7s ( + 1.6 seconds from no hops and + 2.8s from futures based)

The last two roughly line up. Cost of a thread hop ~10us: 100k * 10us * 2 (cause onto and off of I/O) = 2s and the actual difference is 1.6s. So the real costs were slightly lower (8 µs) which makes sense. We know

I was however a little surprised that the async API was 1.2s slower without adding any thread hops.

The most egregious and avoidable time wasters were a silly EventLoop.debugDescription and NSURL in general which I filed as separate issues:
#754
#755

Steps to reproduce

  1. check out weissi@bf7dbeb
  2. swift build -c release
  3. .build/release/AsyncHTTPClientPerfTester

to test without NIO as the executor, comment out these lines: let success = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor() and precondition(success)

If possible, minimal yet complete reproducer code (or URL to code)

[anything to help us reproducing the issue]

See also

Two other issues turned up which should make all of the above APIs significantly faster (could be about 15% better if both were completely fixed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant