You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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)
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
GET /
response justHTTP/1.1 200 ok\r\n\r\nHello World
) HTTP requests to a real server (NIOHTTP1Server
) over loopback on macOS (but usingMultiThreadedEventLoopGroup.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:
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
swift build -c release
.build/release/AsyncHTTPClientPerfTester
to test without NIO as the executor, comment out these lines:
let success = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor()
andprecondition(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)
SelectableEventLoop.debugDescription
#754The text was updated successfully, but these errors were encountered: