Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use an ephemeral port in
bm_asyncio_websocketsinstead of the fixed port 8001Fixes #516
Summary
bm_asyncio_websockets/run_benchmark.pyhard-codes port8001for both theserver and the client:
The default suite runs this benchmark only once, so the problem is not visible
in a normal sequential run. But it prevents two instances from running at the
same time (CI sharding, a custom parallel runner, or simply running the
benchmark twice), and it also fails if an unrelated process already owns port
8001:
Change
Bind port
0(let the kernel pick a free ephemeral port), read the assignedport back from the listening socket, and use it for the client connection:
Why bind
127.0.0.1instead of keeping the empty host?Simply replacing
8001with0while keepinghost=""is not enough withwebsockets==11.0.3. For an empty host it creates two sockets (AF_INET andAF_INET6), and with port
0they receive different ephemeral ports — forexample 39103 and 45903 in my testing.
sockets[0]is then order-dependent andthe client can connect to the wrong address family/port. Binding
127.0.0.1produces a single AF_INET socket and keeps the benchmark server on loopback,
which is all this benchmark needs.
Testing
Tested on Linux x86_64 with CPython
3.16.0a2+dev, pyperformance1.14.0, andwebsockets==11.0.3(the version pinned by the benchmark). The change is notversion-specific.
Result: both complete successfully, no
EADDRINUSE, and no listening socket isleft behind on port 8001:
The workload, transferred data size, and benchmark measurement are unchanged;
only the port selection changes.