Farfetch / loadshedding

A .NET library created to assist the applications in applying LoadShedding techniques and making it easy to configure it
https://farfetch.github.io/loadshedding/
MIT License
88 stars 10 forks source link

Fix queue #19

Closed tiagodaraujo closed 7 months ago

tiagodaraujo commented 7 months ago

Description

Fixes #16

How Has This Been Tested?

Run the load tests and at the end of the tests, the queue and concurrency gauge metrics should report the value zero.

Checklist

Disclaimer

By sending us your contributions, you are agreeing that your contribution is made subject to the terms of our Contributor Ownership Statement

tiagodaraujo commented 7 months ago

I just updated the pull request to remove the traits from Benchmark and Performance projects.

Additionally, I ran the benchmark tests in the main and fix-queue branches. The results showed CPU and Allocated Memory improvements.

The improvement occurs because the queue is now managed with an array instead of a dictionary. Additionally, because the counter mapper for the event argument class no longer exists, the arguments now receive a pointer to IReadOnlyCounter.

| Method                                       | Mean            | Error     | StdDev    | Min       | Max      | Rank | Completed Work Items | Lock Contentions | Allocated |
|--------------------------------------------- |----------------:|----------:|----------:|----------:|---------:|-----:|---------------------:|-----------------:|----------:|
MASTER
| TaskQueueWith1000Items_EnqueueFixedPriority  | 2.133 us        | 1.4382 us | 0.8559 us |  1.200 us | 4.000 us |    1 |                    - |                - | 592 B        |
| TaskQueueEmpty_EnqueueRandomPriority         | 1.730 us        | 0.7866 us | 0.5203 us |  1.150 us | 2.550 us |    1 |                    - |                - | 592 B        |
| TaskQueueWith1000Items_EnqueueRandomPriority | 1.400 us        | 0.1680 us | 0.1000 us |  1.300 us | 1.600 us |    1 |                    - |                - | 592 B        |
| TaskQueueWith1000Items_Dequeue               | 2.244 us        | 1.2578 us | 0.7485 us |  1.700 us | 4.000 us |    1 |                    - |                - | 544 B        |
| TaskQueue_EnqueueNewItem_LimitReached        | 4.878 us        | 3.6680 us | 2.1828 us |  3.400 us | 9.600 us |    2 |                    - |                - | 736 B        |
WITH FIX QUEUE
| TaskQueueWith1000Items_EnqueueFixedPriority  | 1.344 us (-37%) | 0.7282 us | 0.4333 us | 0.9000 us | 2.100 us |    1 |                    - |                - | 592 B (0%)   |
| TaskQueueEmpty_EnqueueRandomPriority         | 1.440 us (-17%) | 0.9487 us | 0.6275 us | 0.8000 us | 2.600 us |    1 |                    - |                - | 592 B (0%)   |
| TaskQueueWith1000Items_EnqueueRandomPriority | 1.012 us (-27%) | 0.1225 us | 0.0641 us | 0.9000 us | 1.100 us |    1 |                    - |                - | 592 B (0%)   |
| TaskQueueWith1000Items_Dequeue               | 3.500 us (+55%) | 2.1769 us | 1.4399 us | 1.7000 us | 6.000 us |    2 |                    - |                - | 472 B (-13%) |
| TaskQueue_EnqueueNewItem_LimitReached        | 2.756 us (-44%) | 1.6142 us | 0.9606 us | 2.0000 us | 4.500 us |    2 |                    - |                - | 592 B (-20%) |

CPU: -16%
Memory: -6%

| Method                           | Mean            | Error   | StdDev  | Min      | Max      | Rank | Gen0   | Completed Work Items | Lock Contentions | Allocated |
|--------------------------------- |----------------:|--------:|--------:|---------:|---------:|-----:|-------:|---------------------:|-----------------:|----------:|
MASTER
| Limiter_Default                  | 283.5 ns        | 10.81 ns | 6.43 ns | 270.6 ns | 291.3 ns |    2 | 0.0572 |               0.0000 |                - | 720 B        |
| Limiter_RandomPriority           | 270.2 ns        |  8.64 ns | 5.72 ns | 260.1 ns | 276.8 ns |    1 | 0.0572 |               0.0000 |                - | 720 B        |
| LimiterMiddleware_Default        | 301.4 ns        |  4.76 ns | 2.83 ns | 298.0 ns | 306.4 ns |    3 | 0.0648 |               0.0000 |                - | 816 B        |
| LimiterMiddleware_RandomPriority | 301.8 ns        |  6.63 ns | 3.47 ns | 294.4 ns | 306.0 ns |    3 | 0.0687 |               0.0000 |                - | 864 B        |
WITH FIX QUEUE
| Limiter_Default                  | 207.0 ns (-27%) |  6.80 ns | 4.50 ns | 198.4 ns | 212.5 ns |    1 | 0.0484 |               0.0000 |                - | 608 B (-16%) |
| Limiter_RandomPriority           | 211.7 ns (-22%) |  8.78 ns | 5.81 ns | 202.1 ns | 217.6 ns |    1 | 0.0484 |               0.0000 |                - | 608 B (-16%) |
| LimiterMiddleware_Default        | 233.0 ns (-23%) |  7.40 ns | 4.89 ns | 226.1 ns | 240.3 ns |    2 | 0.0560 |               0.0000 |                - | 704 B (-14%) |
| LimiterMiddleware_RandomPriority | 239.3 ns (-31%) |  5.73 ns | 3.79 ns | 231.8 ns | 244.6 ns |    3 | 0.0596 |               0.0000 |                - | 752 B (-13%) |

CPU: -26%
Memory: -15%
kikofps commented 7 months ago

Hi @tiagodaraujo , Just releasing this pull request to a beta version, you can find here.