Use atomic types to speedup variable difficulty alogirthm #3

Merged
realaravinth merged 9 commits from optimize-libmcaptha into master 2023-12-31 01:31:22 +05:30
Owner

The actor model currently in use in libmCaptcha is causing a bottleneck that was previously not visible. Protobuf implementation from #1 was yielding very low throughput.

Generating [a flamegraph of that version showed that the AddVisitor message handler was taking up ~59% of the CPU time while the node was hit with the locust benchmark. Keeping track of visitor count is a critical path in the variable difficulty algorithm, but this particular test also involved message serializing/deserializing, request routing and networking, so 59% CPU time seemed odd.

flamegraph

Using CPU concurrency primitives in the place of actors, optimizing memory allocation, and concurrent memory access significantly reduce the footprint of the adding visitor path. The new implementation takes only 0.4% of CPU time on the same benchmark run.

flamegraph of the new solution

The actor model currently in use in libmCaptcha is causing a bottleneck that was previously not visible. Protobuf implementation from #1 was yielding very low throughput. Generating [a flamegraph of that version showed that the [`AddVisitor` message handler](https://github.com/mCaptcha/libmcaptcha/blob/e3f456f35b2c9e55e0475b01b3e05d48b21fd51f/src/master/embedded/counter.rs#L124) was taking up ~59% of the CPU time while the node was hit with the locust benchmark. Keeping track of visitor count is a critical path in the variable difficulty algorithm, but this particular test also involved message serializing/deserializing, request routing and networking, so 59% CPU time seemed odd. ![flamegraph](https://git.batsense.net/mCaptcha/dcache/raw/branch/optimize-libmcaptha/bench/results/v2/libmcaptcha-bottleneck/problem/flamegraph.svg) Using CPU concurrency primitives in the place of actors, optimizing memory allocation, and concurrent memory access significantly reduce the footprint of the adding visitor path. [The new implementation takes only 0.4% of CPU time](https://git.batsense.net/mCaptcha/dcache/raw/branch/optimize-libmcaptha/bench/results/v2/libmcaptcha-bottleneck/solution/flamegraph.svg) on the same benchmark run. ![flamegraph of the new solution](https://git.batsense.net/mCaptcha/dcache/raw/branch/optimize-libmcaptha/bench/results/v2/libmcaptcha-bottleneck/solution/flamegraph.svg)
realaravinth self-assigned this 2023-12-30 14:44:13 +05:30
realaravinth force-pushed optimize-libmcaptha from ef59cd0d01 to c11f89094a 2023-12-30 16:19:32 +05:30 Compare
realaravinth added 1 commit 2023-12-30 18:00:29 +05:30
feat: use DashMap to speedup hashcash implementation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
1f4d3574ab
realaravinth added 1 commit 2023-12-30 20:28:51 +05:30
feat: test variable difficulty driver
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
b8a2a026d6
realaravinth added 1 commit 2023-12-31 01:25:15 +05:30
feat: implement RetrievePow, DeletePow, CacheResult, VerifyCaptchaResult, DeleteCaptchaResult, CaptchaExists& GetVisitorCount RPCs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
fd9ac9d312
realaravinth merged commit 9b281151e7 into master 2023-12-31 01:31:22 +05:30
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mCaptcha/dcache#3
No description provided.