Skip to content

Worker Redesign - #704

Merged
mrocklin merged 48 commits into
dask:masterfrom
mrocklin:worker2
Nov 30, 2016
Merged

mrocklin merged 48 commits into
dask:masterfrom
mrocklin:worker2

Conversation

@mrocklin

@mrocklin mrocklin commented Nov 25, 2016 •

Copy link
Copy Markdown
Member

This replaces the compute logic in the worker with something a bit more complex. See #698 for more details.

@mrocklin

Copy link
Copy Markdown
Member Author

Running into the following error in connect

distributed.worker - ERROR - 'NoneType' object has no attribute 'setsockopt'
Traceback (most recent call last):
  File "/home/mrocklin/workspace/distributed/distributed/worker.py", line 1157, in gather_dep
    stream = yield future
  File "/home/mrocklin/Software/anaconda/lib/python3.5/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/home/mrocklin/Software/anaconda/lib/python3.5/site-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/home/mrocklin/Software/anaconda/lib/python3.5/site-packages/tornado/gen.py", line 1024, in run
    yielded = self.gen.send(value)
  File "/home/mrocklin/workspace/distributed/distributed/core.py", line 327, in connect
    set_tcp_timeout(stream)
  File "/home/mrocklin/workspace/distributed/distributed/core.py", line 224, in set_tcp_timeout
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
AttributeError: 'NoneType' object has no attribute 'setsockopt'

@pitrou

pitrou commented Nov 28, 2016

Copy link
Copy Markdown
Member

No, I hadn't. That explains it :-)

Comment thread distributed/worker.py Outdated
yield gen.with_timeout(timedelta(seconds=1),
[close(stream) for stream in self._listen_streams])
for stream in self._listen_streams:
stream.close()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pitrou any thoughts on why this would cause more file descriptors to be left dangling?

The test distributed/tests/test_client.py::test_open_close_many_workers[Nanny-10-20] is now failing when we create and close many Nannys.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you remove the timeout?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem persists. It also persists if you remove the calls to close(stream) entirely and just call stream.close().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be that closing the stream is confusing another coroutine which is using the stream at the same time. My question is: why did you want to add this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In distributed/tests/test_stress.py::test_stress_scatter_death we close workers during computation. We were finding that connections to killed workers were becoming non-responsive but still remained open. The living worker trying to gather data from the dead worker would wait for a very long time on a living but ineffective stream.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've identified the change that caused the issue.

Comment thread distributed/tests/test_worker2.py Outdated
@@ -0,0 +1,83 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it deliberate to have test_worker and test_worker2?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was convenient to start, but I'll merge them now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@mrocklin mrocklin mentioned this pull request Nov 29, 2016
Comment thread distributed/core.py Outdated
MAX_BUFFER_SIZE = get_total_physical_memory()


CommunicationErrors = (StreamClosedError, socket.error, IOError, RPCClosed)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pitrou do you see any problems with doing this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but you can use EnvironmentError to merge some of these together (apparently RPCClosed derives from IOError).
Still, a question: when is RPCClosed supposedly raised? It looks more like a programmer error (calling a method on a rpc object that's been closed explicitly)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using EnvironmentError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPCClosed ends up being convenient. I don't now recall the original motivation. I suspect that it was difficult to always ensure that the system hadn't closed down in between every yield point and using exceptions was simpler.

This helps us to consistently except several types that can arise when
a stream fails.
@mrocklin

Copy link
Copy Markdown
Member Author

@pitrou if you get a chance I could use some help tracking down a failure in distributed/tests/test_stress.py::test_stress_scatter_death

If you try this test a few times (I tend to run it in a loop) you'll eventually land in a pdb statement. We seem to be waiting on a message that never finishes. Useful things to look at include the following:

  • s.processing will show that there is still an outstanding task
  • ws is all of the currently living workers. One will still have a key in flight
  • ws[address].connections will have a stream that is still open where address is the address of the waiting worker
  • first(ws[address].connections).socket.getpeername() is the location from which we are gathering this data
  • workers holds all of the workers. If you get the right worker and then check w._listen_streams you'll have all of the outstanding streams from that worker.

Sometimes the remote stream appears to be in a bad state. Calling .getpeername() raises an OSError and yet the stream itself does not register as closed. If I add a periodic callback to watch all streams and close them if this occurs then the frequency of failures decreases but doesn't go away. The same situation can occur even when the sockets of both streams appear to be ok.

Anyway, if you have some time to give this a shot I'd appreciate any thoughts you might come up with. I've been trying things here for a long while without much success.

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

I've tried it out. I even got into a case where the socket was still believed to be connected:

(Pdb) pp ws
{'127.0.0.1:33244': <Worker: 127.0.0.1:33244, threads: 1, running: 0, ready: 0, in-flight: 1, waiting: 1>,
 '127.0.0.1:34060': <Worker: 127.0.0.1:34060, threads: 1, running: 0, ready: 0, in-flight: 0, waiting: 0>,
 '127.0.0.1:34650': <Worker: 127.0.0.1:34650, threads: 1, running: 0, ready: 0, in-flight: 0, waiting: 0>}
(Pdb) w1 = ws['127.0.0.1:33244']
(Pdb) pp w1.connections
{<tornado.iostream.IOStream object at 0x7fad78099438>: {'c49ce813f188e6493e3d9a4885782a0f'}}
(Pdb) s1 = first(w1.connections)
(Pdb) pp s1
<tornado.iostream.IOStream object at 0x7fad78099438>
(Pdb) pp s1.socket
<socket.socket fd=28, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 45564), raddr=('127.0.0.1', 34650)>
(Pdb) pp s1.socket.getpeername()
('127.0.0.1', 34650)
(Pdb) w2 = ws['127.0.0.1:34060']
(Pdb) pp w2.connections
{}
(Pdb) w3 = ws['127.0.0.1:34650']
(Pdb) pp w3.connections
{}
(Pdb) !import socket
(Pdb) pp s1.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
0

Yet the connection didn't appear anymore in netstat -tnp.

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

I stand corrected: the connection does appear in netstat -tnp:

(Pdb) pp s1.socket.getpeername()
('127.0.0.1', 34650)
(Pdb) pp s1.socket.getsockname()
('127.0.0.1', 45564)

And the netstat output shows there's some data in the recv queue on the other end (i.e. on the worker being gathered from):

$ netstat -tnp
[...]
tcp      111      0 127.0.0.1:34650         127.0.0.1:45564         ESTABLISHED 10223/python    
[...]

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

tornadoweb/tornado#1901

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

I would recommend applying the following patch: https://gist.github.com/pitrou/f9a19e3b162213ca70169c28582e65e2

@mrocklin

mrocklin commented Nov 30, 2016 via email

Copy link
Copy Markdown
Member Author

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

Ok, I'll try to.

@mrocklin

Copy link
Copy Markdown
Member Author

@pitrou any other comments on this PR? I'm tempted to merge this soon.

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

I just pushed minor style cleanups. I'm ok on the PR, as I said it makes the worker's operation more understandable (though more complicated as well :-)).

@mrocklin

Copy link
Copy Markdown
Member Author

Yeah, I expect we'll run into a few frustrating issues in the near future.

@pitrou

pitrou commented Nov 30, 2016

Copy link
Copy Markdown
Member

At least we don't seem to see any sporadic failures.

@mrocklin
mrocklin merged commit 488f954 into dask:master Nov 30, 2016
@mrocklin

Copy link
Copy Markdown
Member Author

OK, merging.

@mrocklin
mrocklin deleted the worker2 branch November 30, 2016 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants