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

Port selection without using listenany #21

Open
vchuravy opened this issue Feb 1, 2021 · 1 comment
Open

Port selection without using listenany #21

vchuravy opened this issue Feb 1, 2021 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@vchuravy
Copy link
Member

vchuravy commented Feb 1, 2021

UCX.jl/src/UCX.jl

Lines 276 to 281 in 6a369d8

# Choose free port
if port === nothing || port == 0
port_hint = 9000 + (getpid() % 1000)
port, sock = listenany(UInt16(port_hint))
close(sock) # FIXME: https://github.com/rapidsai/ucx-py/blob/72552d1dd1d193d1c8ce749171cdd34d64523d53/ucp/core.py#L288-L304
end

@vchuravy vchuravy added help wanted Extra attention is needed good first issue Good for newcomers labels Feb 1, 2021
@fatteneder
Copy link

Hi,

I thought I give this issue a try. I should say that I don't know much about networking, but perhaps I can learn something from here :)

So I started with some research:

Firstly, I looked into ucx-py under the link mentioned above.
There they use the psutils to gather all used ports into a list and then randomly select one that is not on there.
I could not find any Julia implementation of what psutils.net_connections() does.
But I looked into how psutils.net_connections() works and I (think) what it does is to parse all socket 'files' found under /procs/ to extract the port numbers, cf. https://github.com/giampaolo/psutil/blob/dd57b9a109d6db9a87247d5f47303b87672dfa78/psutil/_pslinux.py#L975-L1004

I then looked into what listenany does: It generates new sockets with incremented port numbers (starting from port_hint) till it finds an used one.

I also found that in the meantime ucx-py changed the implemention, cf. https://github.com/rapidsai/ucx-py/blob/933b373a73d45f7d0a0b91043a6386b396eaebb8/ucp/core.py#L226-L275
I think what they now do is to forward the port selection to the ucx library and the ucp_listener_create method.
I did not check how ucp_listener_create finds an open port ...

Q: Which of the these approaches is the preferred one?
Q: (Naive question) For what reasons should listenany be replaced? Is it expected to be slower than the psutils.net_connections() approach?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants