-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use stored worker names #181
Use stored worker names #181
Conversation
Codecov Report
@@ Coverage Diff @@
## main #181 +/- ##
==========================================
+ Coverage 92.98% 93.08% +0.09%
==========================================
Files 10 10
Lines 442 448 +6
==========================================
+ Hits 411 417 +6
Misses 31 31
Continue to review full report at Codecov.
|
This looks really nice.
|
|
Let's see…
When we use persistent_term at NextRoll… what we do is, in general, store a map as the term. In this case, it would be one per sup with stuff like |
Wow, there's a case of a run passing all tests for OTP24 but not for OTP23 😳 (not mentioning that it all passes locally for me) |
And I was wrong about the line not hit, codecov was showing me the old master as the default. Now correctly comparing The line being missed is https://github.com/NelsonVides/worker_pool/blob/3998f5c2e50713346e058200f9590accec77f577/src/wpool_pool.erl#L399-L409, line 408. |
f2ce26b
to
bb5c59d
Compare
@elbrujohalcon this seems to be fixed, can you take over from here? 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this one and add a ticket to try using persistent_term
for ?WPOOL_WORKERS
.
Excellent, I'll find some spare time to do some prototyping on the persistent_term topic, let me know if you come up with anything in the meantime 💪🏽 |
TL;DR: Using stored names reduces garbage by three and increases the performance (of finding the worker) by 4.
This is achieved by storing the worker names on an ets table with keys
{SupervisorName, Index}
and values the final atom representing the name, instead of calculating this atom name again and again. I suspect this might also have somehow better concurrency characteristics, as generating the name generates atoms, and therefore needs to grab locks on the atom table, which is not optimised for writes, even if the write is idempotent as the atom already exists, but this one is mostly guessing. Sequential performance is surely much better 🙂Not sure of the preferred conventions in this project, I'm all open for changes, mostly I'm proposing the idea more than the exact code 😇
Operating System: Ubuntu 20.04.3 in server mode
CPU Information: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Number of Available Cores: 12
Available memory: 30.99 GB
Erlang 24.1.7
Running on two separate, freshly started VMs, the command
fprof:apply(fun wpool_bench:run_tasks/3, [[{small, 100}], best_worker, []]).
on bothmain
and on this branch, bears the following results:Using worker names from upstream:
Using stored worker names
Also running
wpool_bench:run_tasks([{small, 10000}], best_worker, []).
on a VM spawned asERL_FLAGS="+JPperf true +S 1" rebar3 shell
and then runningReturns 51% of time on
worker_pool:worker_name/2
for main, and 19% of time for the same function in this branch.main
stored
Attached the two perf reports for both runs, with flame graphs attached: wpool_perf_flamegraphs.zip