Replace mutex in config service with atomic config entry / semaphore#9
Replace mutex in config service with atomic config entry / semaphore#9
Conversation
chamons
left a comment
There was a problem hiding this comment.
TIL of arc-swap
I think the only thing that scares me is that unwrap in src/fetch/service.rs, but this is a bit in the weeds of multithreading programming past my expertise.
Should there be some sort of benchmark included to show that this improves contention performance? I could hack one up if needed, but it shouldn't be too hard. Make 100 or 200 readers in parallel should hit it?
|
@chamons I determined that the unwrap is safe there because the docs of Semaphore's I made a benchmark (it was quite a journey, I struggled a bit to figure out async benchmark options), and my results are these: The benchmark preps a simulated environment where a cache is in place to bypass the first HTTP request so we can see the real difference between the synchronized reads. (My original baked "benchmark" script ran for 100000 concurrent tasks where the difference was much more noticeable 😄) |
chamons
left a comment
There was a problem hiding this comment.
That seems like an overall win to me.
|
I do wonder, if you increase the number of concurrent readers does the time go up exponentially or faster than linearly? |
|
@chamons I've added a steady increase in the reader count to the benchmark, these are the results: Old: New: The execution times still increase faster than linearly but with a lower amount. |
Describe the purpose of your pull request
This PR refines the synchronization mechanism in
ConfigService. Rather than aMutex, we now use atomic operations on the in-memory config data andSemaphoreto ensure only one HTTP call is active at a time.Related issues (only if applicable)
Requirement checklist (only if applicable)