danielealbano / cachegrand

cachegrand - a modern data ingestion, processing and serving platform built for today's hardware
BSD 3-Clause "New" or "Revised" License
975 stars 34 forks source link

Initial implementation transactions in new hastable mpmc #285

Closed danielealbano closed 1 year ago

danielealbano commented 1 year ago

This PR introduces a basic transaction support for the new mpmc hashtable:

This PR is extremely important because it introduces a blazing fast new data structure, the slots_bitmap_mpmc which performs extremely well under contention. The main idea is that each transaction is just a slot of the bitmap and each thread will search in this bitmap first in its own shard (as the bitmap allows localized searches) and then in the whole bitmaps as fallback.

The result is that in a normal situation, where slots are available for the thread, to acquire and release 51200 slots per threads it takes just a few nanoseconds (more details in benches/bench-slots-bitmap-mpmc.cpp)

threads:1 15099228 ns
threads:2 1027204 ns
threads:4 74470 ns
threads:8 5860 ns
threads:16 499 ns
threads:32 42 ns

With 4 thread and in avg 800k ops/s in total (therefore potentially 800k transactions/s) the time required would be 1.16ms, an average overhead of 1.45ns per transaction to be acquired and released meanwhile with with just 1 thread and in avg 200k ops/s would be 295us. In both cases the time to acquire and release a transaction id is close enough to zero to be considered irrelevant!

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 94.95% and project coverage change: +0.15 :tada:

Comparison is base (73325e3) 83.01% compared to head (3264b05) 83.15%.

:exclamation: Current head 3264b05 differs from pull request most recent head 354a3f7. Consider uploading reports for the commit 354a3f7 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #285 +/- ## ========================================== + Coverage 83.01% 83.15% +0.15% ========================================== Files 158 161 +3 Lines 10310 10524 +214 ========================================== + Hits 8558 8751 +193 - Misses 1752 1773 +21 ``` | Flag | Coverage Δ | | |---|---|---| | unittests | `83.15% <94.95%> (+0.15%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano) | Coverage Δ | | |---|---|---| | [...rc/data\_structures/hashtable/spsc/hashtable\_spsc.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2RhdGFfc3RydWN0dXJlcy9oYXNodGFibGUvc3BzYy9oYXNodGFibGVfc3BzYy5j) | `94.51% <ø> (ø)` | | | [...rc/data\_structures/hashtable\_mpmc/hashtable\_mpmc.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2RhdGFfc3RydWN0dXJlcy9oYXNodGFibGVfbXBtYy9oYXNodGFibGVfbXBtYy5j) | `94.28% <80.00%> (+0.22%)` | :arrow_up: | | [...a\_structures/slots\_bitmap\_mpmc/slots\_bitmap\_mpmc.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2RhdGFfc3RydWN0dXJlcy9zbG90c19iaXRtYXBfbXBtYy9zbG90c19iaXRtYXBfbXBtYy5j) | `94.03% <94.03%> (ø)` | | | [...a\_structures/slots\_bitmap\_spsc/slots\_bitmap\_spsc.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2RhdGFfc3RydWN0dXJlcy9zbG90c19iaXRtYXBfc3BzYy9zbG90c19iaXRtYXBfc3BzYy5j) | `95.70% <95.70%> (ø)` | | | [...a\_structures/slots\_bitmap\_mpmc/slots\_bitmap\_mpmc.h](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL2RhdGFfc3RydWN0dXJlcy9zbG90c19iaXRtYXBfbXBtYy9zbG90c19iaXRtYXBfbXBtYy5o) | `96.97% <96.97%> (ø)` | | | [src/network/channel/network\_channel\_tls.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL25ldHdvcmsvY2hhbm5lbC9uZXR3b3JrX2NoYW5uZWxfdGxzLmM=) | `1.20% <0.00%> (-0.16%)` | :arrow_down: | | [src/network/network\_tls.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL25ldHdvcmsvbmV0d29ya190bHMuYw==) | `71.83% <0.00%> (ø)` | | | [src/network/io/network\_io\_common\_tls.c](https://codecov.io/gh/danielealbano/cachegrand/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano#diff-c3JjL25ldHdvcmsvaW8vbmV0d29ya19pb19jb21tb25fdGxzLmM=) | `100.00% <0.00%> (+100.00%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Daniele+Salvatore+Albano)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.