[lib] replace config thread-local with global and thread lock#218
Conversation
f418831 to
35e7709
Compare
| core_transforms.RunConfig._load_config_from_file() | ||
|
|
||
|
|
||
| # FIXME: other test files (test_pubsub_message_manager.py and others) patch |
There was a problem hiding this comment.
Just confirming: this is because our tests run in parallel and even resetting the value to None won't guarantee it will be empty when we call .get() if another test loads the config first?
There was a problem hiding this comment.
@shireen-bean I suspect (@DanSimon can correct me if I'm wrong) that this is because patches are "leaking" from other tests. FWIW our tests are not run in parallel.
There was a problem hiding this comment.
I think I've gotten around the issue by adding some patcher.stop() calls. I've updated the PR with my changes, tests all pass so it definitely works, though I'm open if there's another approach we should take.
|
The changes and explanations make sense to me! Not going to approve tho because would like multiple sets of eyes before the ✅ |
7a091f3 to
276581d
Compare
| Changed | ||
| ******* | ||
|
|
||
| * Klio's config file is now read from disk once per worker instead of once per thread (See `PR 218 <https://github.com/spotify/klio/pull/218>` _). |
There was a problem hiding this comment.
it looks like there's a space between the 2nd back tick and the underscore for the link
There was a problem hiding this comment.
Ah yeah the link is broken: https://klio--218.org.readthedocs.build/en/218/reference/lib/changelog.html#changed
econchick
left a comment
There was a problem hiding this comment.
LGTM - just need to fix that link in the changelog
276581d to
6818506
Compare
When doing some benchmarking on streaming Dataflow, it was observed that if a job was started with large backlog of messages in Pubsub, the job would take a while to start processing messages and seem to have some throughput problems.
It was determined that the underlying cause was twofold.
Therefore, this PR replaces the thread-local storage with simply a single global variable guarded by a thread lock. This means that now config is only read from disk once per worker and in a thread-safe manner.
This was tested extensively on Dataflow and with backlogs of over 100k messages, all startup problems were largely eliminated. Beam will still start many threads but they no longer pile up loading config and processing begins shortly after the first thread is spawned.
Only one small issue: I added a simple unit test but due to how we mock out
RunConfigin other tests, the test is affected and doesn't run properly. I unsuccessfully made a couple quick attempts to fix, so we'll have to go back and figure out a better way to handle config mocking (or eliminate the need to begin with) if we want to not skip the test.Checklist for PR author(s)
[cli] Fixes bugs in 'klio job fake-cmd'.docs/src.docs/src/reference/<package>/changelog.rst.