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_tcpinstead of the fixed port 8882Fixes #514
Summary
asyncio_tcpandasyncio_tcp_sslboth runpyperformance/data-files/benchmarks/bm_asyncio_tcp/run_benchmark.py, whichhard-codes
127.0.0.1:8882. Becausebm_asyncio_tcp_ssl.tomlselects the SSLvariant with
extra_opts = ["--ssl"], the two benchmarks use the same serverscript and the same port, so one of them dies with
EADDRINUSEwhen they runconcurrently:
This also makes the benchmark fail whenever an unrelated process is listening on
port 8882.
Change
Bind port
0(let the kernel pick a free ephemeral port) and read the assignedport back from the listening socket. The client then connects to that port.
The change covers both the plain and the SSL code path because both are handled
by the same
main()function.Why not probe for a free port first?
A common alternative is to create a temporary socket, bind it to port
0, readthe port, close it, and then bind the real server to that port. That has a
TOCTOU race: another process can take the port between the close and the second
bind. Binding port
0on the real server socket avoids the race entirely — thelistening socket owns the port, and
getsockname()reports what the kernelassigned.
bm_tornado_httpalready uses the same idea (bind_sockets(0, ...)plusgetsockname()).Testing
Tested on Linux x86_64 with CPython
3.16.0a2+devand pyperformance1.14.0.The change is not version-specific.
Result: both complete successfully, no
EADDRINUSE, and no listening socket isleft behind on 8882 after the run:
python -m pyperformance run -b asyncio_tcp_ssl -f -o /tmp/asyncio_tcp_ssl.json # asyncio_tcp_ssl: Mean +- std dev: 2.21 sec +- 0.07 secpyperformance runprocess per benchmark, each pinned to one CPU core. 99passed; the only failure was
dask, which is unrelated to this change(cloudpickle
3.1.2looks up the removedDELETE_GLOBALopcode on Python3.16). No port-conflict errors appeared in any log, and ports 8001/8882 were
free after the run.
The workload, transferred data size, and benchmark measurement are unchanged;
only the port selection changes.