Repository navigation
Allow range of ports to be specified for Workers - #3704
Conversation
|
Thanks for this @jrbourbeau . It's not every day that you're able to fix an issue below I wonder if it's possible to make this change lower down, in the |
An oldie, but a goody : )
Yeah, that's a great point. We could push this down into the |
|
I've moved the port range logic down into the and using the Python API w = await Worker(..., port="9500:9600")The CI test failures are from a known flaky test ( |
TomAugspurger
left a comment
There was a problem hiding this comment.
Overall looks nice, just a couple questions.
|
|
||
| await self.listen( | ||
| self._start_address, **self.security.get_listen_args("worker") | ||
| ports = parse_worker_ports(self._start_port) |
There was a problem hiding this comment.
Slightly concerned with the amount of duplication between here and the Nanny. What are your thoughts?
There was a problem hiding this comment.
I spent some time trying to push this logic down into the underlying Server.listen call, but things got somewhat complicated so I decided to punt on it for now. I'll revisit this to see if we can do it in a simple way
There was a problem hiding this comment.
I'm completely fine with things as is if it's not straightforward to dedpulicate. I didn't look too closely.
| self._start_address, **self.security.get_listen_args("worker") | ||
| ) | ||
| ports = parse_worker_ports(self._start_port) | ||
| for port in ports: |
There was a problem hiding this comment.
Just for my understanding, does each nanny attempt to connect to the first port? One succeeds and the rest try the second? And so on?
There was a problem hiding this comment.
Yes, that's exactly what happens
|
|
||
| await self.listen( | ||
| self._start_address, **self.security.get_listen_args("worker") | ||
| ports = parse_worker_ports(self._start_port) |
There was a problem hiding this comment.
I'm completely fine with things as is if it's not straightforward to dedpulicate. I didn't look too closely.
|
It looks like the failing tests are known flakey tests. |
| ) | ||
| port = list(range(port_start, port_stop + 1)) | ||
|
|
||
| return port |
There was a problem hiding this comment.
This could be used for nannies schedulers or other servers I think. Maybe it should move to utils and we should remove worker from the name. Also, can I ask for a small docstring, maybe with a couple of examples?
Should it always return a list of integers for consistency, or would that complicate other parts of the codebase?
There was a problem hiding this comment.
+1 to moving to utils and adding documentation
Right now this function either returns a list of integers or the 1-element list [None]. I decided to keep the None option as to not break existing code paths where if None is received as a port, then some configured default port is used
|
|
||
| self._start_address = addresses_from_user_args( | ||
| host=self._start_host, | ||
| port=parse_worker_ports(self._start_port), |
There was a problem hiding this comment.
I'm not sure that this is what we want. If I provide a range like "8000:9000" then I think that this will provide a list of 1000 addresses on which to listen. Is that correct? If so, that could quickly become problematic.
Instead, I would expect the port logic to occur around when we try to listen on a port, and find it to be busy.
There was a problem hiding this comment.
It will provide a list of 1000 possible addresses to listen on but when we then make the call to self.listen it will start to loop through the 1000 addresses until we find one that is open, create a single listener for that address, and then return. So each listen call results in, at most, one listener being created. There's an added test, distributed/tests/test_core.py::test_multiple_addresses, which demonstrates this behavior.
I agree if we created 1000 listeners here that would be problematic. Do you think the behavior outlined above is still problematic?
There was a problem hiding this comment.
OK, I think that there might be a slight conflict here that may be my fault.
In #3288 I added the ability for the Scheduler to listen on many addresses at once. This is where the addresses_from_user_args function came from. However I never took the time to extend this functionality over to worker/nanny. The intention here was that we would iterate over many addresses from self._start_address and listen on all of them.
In this PR we're now reusing that same mechanism, but for a different purpose saying "listen on the first one that works". Everything today is fine, but the moment that we try to either have multiple networks active on the workers, or use a port range on the scheduler, we'll run into a biggish conflict I think.
There was a problem hiding this comment.
Alright, thanks for the additional context. We would indeed have a conflict if we wanted to use, say, a port range and multiple interfaces on a Worker.
I'll roll back the recent changes that moved the "listen on the first address that works" logic to Server.listen and instead keep an explicit for-loop over multiple ports in the Worker/Nanny classes like in 2d7162e. I think having a single input address for Server.listen will help us better isolate any port range and/or multiple interface logic moving forward.
| ports = parse_ports(self._start_port) | ||
| for port in ports: | ||
| start_address = address_from_user_args( | ||
| host=self._start_host, | ||
| port=port, | ||
| interface=self._interface, | ||
| protocol=self._protocol, | ||
| security=self.security, | ||
| ) | ||
| try: | ||
| await self.listen( | ||
| start_address, **self.security.get_listen_args("worker") | ||
| ) | ||
| except OSError as e: | ||
| if len(ports) > 1 and e.errno == errno.EADDRINUSE: | ||
| continue | ||
| else: | ||
| raise e | ||
| else: | ||
| self._start_address = start_address | ||
| break | ||
| else: | ||
| raise ValueError( | ||
| f"Could not start Worker on host {self._start_host}" | ||
| f"with port {self._start_port}" | ||
| ) |
There was a problem hiding this comment.
Does it make sense to try to move this logic into Server.listen? It would mean changing the interface of that method to something like the following I think.
async def listen(host, port, interface, protocol, security, ...)Then maybe we can pull `address_from_user_args in, and apply this logic to the Scheduler and other future systems as well?
There was a problem hiding this comment.
(sorry to be late in reviewing by the way, if you want to just move forward and merge this that's fine with me too)
There was a problem hiding this comment.
For now I'd prefer to have this merged in as is, and then address the move to Server.listen in a follow-up PR
This PR allows multiple ports to be specified for
WorkerandNannyprocesses created with thedask-workercommand. Here we allows users to specify the starting and stopping points for a sequential range of available ports like so<first-port>:<last-port>. So, for example,--worker-ports 9500:9600would use ports9500,9501, ...,9599,9600.This can be useful when using systems where a specific range of ports have been whitelisted for use. There was some discussion over in #899 where there seemed to be interest in adding this capability
Fixes #899