Repository navigation
Offload (de)serialization to a separate thread - #1218
Conversation
This is conditioned on the input size, to avoid increasing the overhead of processing small administrative messages.
mrocklin
left a comment
There was a problem hiding this comment.
This seems like a nicely simple change. We should try running this through some benchmarks eventually.
|
|
||
|
|
||
| def offload(fn, *args, **kwargs): | ||
| return _offloader.submit(fn, *args, **kwargs) |
There was a problem hiding this comment.
Why the need for the Offloader class here? Would a raw ThreadPoolExecutor work just as well? Is this necessary because of the finalize cleanup code? Does finalize require being part of a class?
There was a problem hiding this comment.
There is no real need, but I find it nice to avoid too many global variables.
There was a problem hiding this comment.
We're going to have a global _offloader regardless. Adding another for the finalizer doesn't seem that bad to me.
I generally prefer to stick to using common types for things when possible. I personally find it difficult to quickly understand code when it creates many of its own abstractions.
| class Offloader(object): | ||
|
|
||
| def __init__(self): | ||
| self.executor = ThreadPoolExecutor(max_workers=1) |
There was a problem hiding this comment.
We might want a couple of workers here? We do accept multiple messages concurrently. Having multiple threads here might help fast messages get through in the presence of large messages.
There was a problem hiding this comment.
Well, that depends. On the workers, that might overcommit worker threads? (do we care about this issue?)
The problem is we need a heuristic. Something like min(4, cpu_cores())?
There was a problem hiding this comment.
In my experience heavy communication and heavy computation rarely overlap. In the case that they do I'd rather have communication take precedence. I think it makes sense to have somewhere between 2-4 communication threads. Although really all of this is probably premature before we find some application that cares.
There was a problem hiding this comment.
Well, having multiple threads early might help expose any potential issues.
|
(Travis-Ci seems not to trigger any builds from Github anymore) Edit: it came back |
|
This looks good to me. +1. I ran both a basic small-data benchmark and a more communication heavy benchmark (with chunks > size 10MB) and things seemed about the same. |
|
Thank you. I'm merging now. |
This is conditioned on the input size, to avoid increasing the overhead of processing
small administrative messages.