You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Capturing and logging stdout/stderr on workers #2033
For various reasons, it is nice to be able to use stdout and stderr on workers and see the results. This can be useful in simplistic debugging attempts, using 3rd party code that already prints to one (or both) of these, etc. However it appears stdout and stderr are ignored in these settings currently.
A very useful feature would be to capture stdout and stderr on the worker and redirect them to a logger. One simple option would be to use the loggers distributed.worker.stdout and distributed.worker.stderr with info level messages. These loggers seem to be unused now and redirecting to them seems to work fine. This would at least give users one reasonable way to get this information.
Reacted by Christian Hudon, Daniel Severo, Guillaume Eynard-Bontemps, Shane Keller, Chris Byrohl, Christoph Giese, Pierre Augier, Pedro Crespo-Valero, Benjamin Fry, Bob Colner and 5 more
I agree that getting stdout and stderr is a common desire. It is often handled by the supporting job scheduler (like SGE/SLURM/Kubernetes/Yarn) but I can understand that a dask-centric solution might also be valuable.
Currently the workers maintain loggers that they can publish on the dask dashboard info pages, however these only collect lines recorded by the logging module. Perhaps this could be hijacked though.
If more short-term or immediate support is desired then this is also the kind of thing that PubSub could probably implement in short-order.
Thus far that hasn't been my experience. @TomAugspurger and I ran into this last week in the Kubernetes backed Distributed cluster. Also have had this issue with dask-drmaa and the LocalCluster. With dask-drmaa, stdout/stderr are hooked into distributed's logging system. Not sure if how things are configured logging-wise is blocking this output from getting through or if there is something I need to be doing at a configuration level. That said, this is probably ok to keep things structured. Just would like stdout/stderr to be included in these logs somehow.
Yeah, hijacking stdout/stderr from functions run with Distributed SGTM. Have come up with some code for a decorator that may act as a good initial prototype. It works for now, but wouldn't be surprised if there are better things we should be doing to get this functionality into distributed.
Did a little digging in the code. FWICT it appears the run method of _WorkItem is where functions are run. Would it make sense to capture stdout and stderr at this level? Any thoughts on how we might want to do this?
A random walk-by comment. Collecting a logs of a large number of workers to a single destination does not feel easy to make scalable.
If the purpose is to monitor the progress of the workers with granularity smaller than a unit of work, then maybe this can be done in a more controlled way -- e.g. when the workers report the health to the master, it can also report the current progress (e.g. as an arbitrary string) inside the current unit of work?
Dask already batches small messages sent between scheduler and workers, so in practice what you are suggesting will likely happen anyway. We've had to build up infrastructure to efficiently pass around many small messages. We now get to rely on that infrastructure.
For publicly available APIs, I would probably recommend the Pub/Sub system
to move logs around.
If people wanted to use non-public APIs I would use
Worker.batched_stream.send
In #5217 (the ticket is a bit cryptic, below example pseudo code) we built a functionality to support "remote printing" that may be useful for some people in here. It appears we never updated the docs appropriately, at least I couldn't find it.
If you run a function on a remote worker and are using the distributed print function, it will print this message on stdout of your worker and forwards the message to the client and prints it on the client as well. The same works for warn as the stdlib warn works and you can build your own client handlers using Client.subscribe_topic in combination with Worker.log_event.
This obviously only scales to a certain level as was already pointed out with collecting logging information in a central place.
At the very least the "simplistic debugging attempt" use case should be covered by this. For proper logging, I would not recommend using this.
@ntonasa See my gist here for a proof-of-concept of how to use the subscribe mechanism that was added in #5217 to configure the forwarding of arbitrary logging statements by tasks running on workers to the client session.
@ntonasa See my gist here for a proof-of-concept of how to use the subscribe mechanism that was added in #5217 to configure the forwarding of arbitrary logging statements by tasks running on workers to the client session.
I am using a similar approach (handle/log_event/subscribe_topic) on a private repo and would love to see your gist merged.
I can help test any PR if needed.
Cool, thanks @epizut. I haven't heard back from the the dask maintainers on whether they'd be open to such a PR, but I'm happy to quickly put one together... most of it is in that gist, I'll just need to whip together some unit tests and docs. Can ping you when there's something to test.
My approach will basically be to take the forward_logging() function from that gist and convert it to an instance method on Client objects, perhaps with some additional edge case handling (like what happens if you call it twice).
FWIW the original idea behind this issue was to have workers capture print calls and log them in their own specific worker log. Not necessarily aggregate them. Users can already inspect worker logs through the dashboard. Idk if that is still of interest to others, but this might impose less of a burden and be more scalable.
@epizut I have a PR up at #7276 -- feel free to test it if you'd like. See the docstr of Client.forward_logging() for examples.
@jakirkham Thanks for clarifying. It's a little confusing because there are a few ideas flying around:
Capture print calls and forward them to the client
Capture logging calls and forward them to the client
Capture print calls and log them locally in the worker without forwarding to the client
My PR really addresses (2), while distributed.print() addresses (1) in a selective way (i.e., user-chosen print calls, not all of stdout), and now @mrocklin's idea #7202 would address (1) on all worker stdout (non-selective) and would also be the foundation for an implementation of (3), which would presumably use a similar Tee-like object in a WorkerPlugin.
Activity
mrocklin commentedon Jun 7, 2018
I agree that getting stdout and stderr is a common desire. It is often handled by the supporting job scheduler (like SGE/SLURM/Kubernetes/Yarn) but I can understand that a dask-centric solution might also be valuable.
Currently the workers maintain loggers that they can publish on the dask dashboard info pages, however these only collect lines recorded by the logging module. Perhaps this could be hijacked though.
If more short-term or immediate support is desired then this is also the kind of thing that PubSub could probably implement in short-order.
jakirkham commentedon Jun 7, 2018
Thus far that hasn't been my experience. @TomAugspurger and I ran into this last week in the Kubernetes backed Distributed cluster. Also have had this issue with
dask-drmaaand theLocalCluster. Withdask-drmaa,stdout/stderrare hooked intodistributed's logging system. Not sure if how things are configured logging-wise is blocking this output from getting through or if there is something I need to be doing at a configuration level. That said, this is probably ok to keep things structured. Just would likestdout/stderrto be included in these logs somehow.Yeah, hijacking
stdout/stderrfrom functions run with Distributed SGTM. Have come up with some code for a decorator that may act as a good initial prototype. It works for now, but wouldn't be surprised if there are better things we should be doing to get this functionality intodistributed.Details
How do you see this working with PubSub?
jakirkham commentedon Jun 10, 2018
Did a little digging in the code. FWICT it appears the
runmethod of_WorkItemis where functions are run. Would it make sense to capturestdoutandstderrat this level? Any thoughts on how we might want to do this?rainwoodman commentedon Nov 3, 2019
A random walk-by comment. Collecting a logs of a large number of workers to a single destination does not feel easy to make scalable.
If the purpose is to monitor the progress of the workers with granularity smaller than a unit of work, then maybe this can be done in a more controlled way -- e.g. when the workers report the health to the master, it can also report the current progress (e.g. as an arbitrary string) inside the current unit of work?
mrocklin commentedon Nov 3, 2019
Dask already batches small messages sent between scheduler and workers, so in practice what you are suggesting will likely happen anyway. We've had to build up infrastructure to efficiently pass around many small messages. We now get to rely on that infrastructure.
rainwoodman commentedon Nov 3, 2019
Do you mean reporting the progress with something like this from the worker client?
https://distributed.dask.org/en/latest/api.html#distributed.Client.set_metadata
mrocklin commentedon Nov 3, 2019
anna-geller commentedon May 31, 2022
Is this still an open issue?
fjetter commentedon Jun 1, 2022
In #5217 (the ticket is a bit cryptic, below example pseudo code) we built a functionality to support "remote printing" that may be useful for some people in here. It appears we never updated the docs appropriately, at least I couldn't find it.
If you run a function on a remote worker and are using the distributed print function, it will print this message on stdout of your worker and forwards the message to the client and prints it on the client as well. The same works for
warnas the stdlib warn works and you can build your own client handlers usingClient.subscribe_topicin combination withWorker.log_event.This obviously only scales to a certain level as was already pointed out with collecting logging information in a central place.
At the very least the "simplistic debugging attempt" use case should be covered by this. For proper logging, I would not recommend using this.
ntonasa commentedon Sep 15, 2022
Any news on this one? It affects other projects as well, like Prefect
PrefectHQ/prefect#5850
maxbane commentedon Oct 15, 2022
@ntonasa See my gist here for a proof-of-concept of how to use the subscribe mechanism that was added in #5217 to configure the forwarding of arbitrary logging statements by tasks running on workers to the client session.
epizut commentedon Oct 17, 2022
I am using a similar approach (handle/log_event/subscribe_topic) on a private repo and would love to see your gist merged.
I can help test any PR if needed.
maxbane commentedon Oct 17, 2022
Cool, thanks @epizut. I haven't heard back from the the dask maintainers on whether they'd be open to such a PR, but I'm happy to quickly put one together... most of it is in that gist, I'll just need to whip together some unit tests and docs. Can ping you when there's something to test.
My approach will basically be to take the
forward_logging()function from that gist and convert it to an instance method onClientobjects, perhaps with some additional edge case handling (like what happens if you call it twice).jakirkham commentedon Oct 18, 2022
FWIW the original idea behind this issue was to have workers capture
printcalls and log them in their own specific worker log. Not necessarily aggregate them. Users can already inspect worker logs through the dashboard. Idk if that is still of interest to others, but this might impose less of a burden and be more scalable.maxbane commentedon Nov 9, 2022
@epizut I have a PR up at #7276 -- feel free to test it if you'd like. See the docstr of
Client.forward_logging()for examples.@jakirkham Thanks for clarifying. It's a little confusing because there are a few ideas flying around:
My PR really addresses (2), while
distributed.print()addresses (1) in a selective way (i.e., user-chosen print calls, not all of stdout), and now @mrocklin's idea #7202 would address (1) on all worker stdout (non-selective) and would also be the foundation for an implementation of (3), which would presumably use a similarTee-like object in a WorkerPlugin.