Using a worker instead of a thread per batch - #920
Conversation
|
(comment updated) This is master... with the following patch: I verified that it has the threading code enabled. This is this PR: The We have a nice performance curve that peaks at just about the L2 cache size. This is on one particular machine (GNU GCC 8, Skylake, Linux) but the point is that the code in master for I think that the gist of the difference with the new code is that instead of using a thread per batch, we use a single thread. This helps tremendously. The new code reaches more or less the same best speed, but with 5x smaller batches. Evidently, this translates into lower memory usage, but importantly, in less stress on the cache. The downside is that the new code is more complicated and harder to get right. |
jkeiser
left a comment
There was a problem hiding this comment.
I don't see anything particularly concerning, and acquiring resources less often seems like a positive thing in any case :) A few questions/comments in there.
|
BTW here are the speeds without threading... and with threading... So we get a clean 50% boost in the speed when using a second thread. That's not new to this PR but it important as a motivation. We are not using a thread for fun... it definitively buys us performance. Going 1.5 x faster when using two cores is pretty much what you'd hope for in general. |
|
Ok. Let us merge. |
In the
parse_manyfunction, we have one thread doing the stage 1, while the main thread does stage 2. So if stage 1 and stage 2 take half the time, theparse_manycould run at twice the speed. It is unlikely to do so. Still, we see benefits of about 40% due to threading.To achieve this interleaving, we load the data in batches (blocks) of some size. In the current code (master), we create a new thread for each batch. Thread creation is expensive so our approach only works over sizeable batches. This PR improves things and makes
parse_manyfaster when using small batches.This PR makes
parse_manybeneficial over small datasets. It also makes us less dependent on the thread creation time.Unfortunately, it is going to be difficult to say anything definitive in general. The cost of creating a thread varies widely depending on the OS. On some systems, it might be cheap, in others very expensive. It should be expected that the new code will depend less drastically on the performances of the underlying system, since we create juste one thread.
Fixes #529