Skip to content
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

Provide a common atomic Rate Limiter implementation #560

Merged
merged 12 commits into from
Sep 4, 2024
Merged

Conversation

bwoebi
Copy link
Contributor

@bwoebi bwoebi commented Jul 31, 2024

As opposed to #552, this implementation is based on atomics and can be used for communication via shared memory.

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 82.25256% with 52 lines in your changes missing coverage. Please review.

Project coverage is 72.88%. Comparing base (d4dd94f) to head (01e7245).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #560      +/-   ##
==========================================
+ Coverage   72.79%   72.88%   +0.08%     
==========================================
  Files         243      245       +2     
  Lines       34683    34951     +268     
==========================================
+ Hits        25249    25473     +224     
- Misses       9434     9478      +44     
Components Coverage Δ
crashtracker 20.44% <ø> (ø)
datadog-alloc 98.73% <ø> (ø)
data-pipeline 90.12% <ø> (ø)
data-pipeline-ffi 0.00% <ø> (ø)
ddcommon 82.82% <95.68%> (+0.71%) ⬆️
ddcommon-ffi 68.11% <ø> (ø)
ddtelemetry 59.02% <ø> (ø)
ipc 83.61% <73.37%> (-0.40%) ⬇️
profiling 84.26% <ø> (ø)
profiling-ffi 77.42% <ø> (ø)
serverless 0.00% <ø> (ø)
sidecar 40.13% <75.00%> (-0.02%) ⬇️
sidecar-ffi 0.00% <ø> (ø)
spawn-worker 50.36% <ø> (ø)
tinybytes 91.66% <ø> (ø)
trace-mini-agent 70.88% <ø> (ø)
trace-normalization 98.25% <ø> (ø)
trace-obfuscation 95.73% <ø> (ø)
trace-protobuf 77.67% <ø> (ø)
trace-utils 93.00% <ø> (ø)

@pr-commenter
Copy link

pr-commenter bot commented Jul 31, 2024

Benchmarks

Comparison

Benchmark execution time: 2024-09-04 10:57:05

Comparing candidate commit 01e7245 in PR branch bob/rate_limiter with baseline commit d4dd94f in branch main.

Found 25 performance improvements and 1 performance regressions! Performance is the same for 24 metrics, 2 unstable metrics.

scenario:benching string interning on wordpress profile

  • 🟩 execution_time [-3.642µs; -3.562µs] or [-2.601%; -2.544%]

scenario:credit_card/is_card_number/

  • 🟩 execution_time [-401.840ns; -401.676ns] or [-24.898%; -24.888%]
  • 🟩 throughput [+205318274.145op/s; +205401727.721op/s] or [+33.137%; +33.150%]

scenario:credit_card/is_card_number/ 3782-8224-6310-005

  • 🟩 execution_time [-8.883µs; -8.479µs] or [-7.221%; -6.892%]
  • 🟩 throughput [+603173.480op/s; +633688.395op/s] or [+7.420%; +7.796%]

scenario:credit_card/is_card_number/ 378282246310005

  • 🟩 execution_time [-4.687µs; -4.358µs] or [-4.137%; -3.847%]
  • 🟩 throughput [+354067.267op/s; +381554.401op/s] or [+4.011%; +4.322%]

scenario:credit_card/is_card_number/37828224631

  • 🟩 execution_time [-400.815ns; -399.640ns] or [-24.832%; -24.759%]
  • 🟩 throughput [+203958573.569op/s; +204579773.414op/s] or [+32.921%; +33.021%]

scenario:credit_card/is_card_number/378282246310005

  • 🟩 execution_time [-3.948µs; -3.612µs] or [-3.613%; -3.306%]
  • 🟩 throughput [+313728.565op/s; +343428.321op/s] or [+3.427%; +3.752%]

scenario:credit_card/is_card_number/37828224631000521389798

  • 🟩 execution_time [-10.549µs; -10.410µs] or [-9.417%; -9.293%]
  • 🟩 throughput [+915146.796op/s; +927380.384op/s] or [+10.252%; +10.389%]

scenario:credit_card/is_card_number_no_luhn/

  • 🟩 execution_time [-401.759ns; -401.573ns] or [-24.894%; -24.882%]
  • 🟩 throughput [+205259038.336op/s; +205352653.920op/s] or [+33.127%; +33.142%]

scenario:credit_card/is_card_number_no_luhn/ 3782-8224-6310-005

  • 🟩 execution_time [-5.516µs; -5.366µs] or [-5.684%; -5.529%]
  • 🟩 throughput [+603386.540op/s; +620824.586op/s] or [+5.856%; +6.026%]

scenario:credit_card/is_card_number_no_luhn/ 378282246310005

  • 🟩 execution_time [-2.702µs; -2.542µs] or [-3.070%; -2.888%]
  • 🟩 throughput [+338233.367op/s; +359294.613op/s] or [+2.977%; +3.163%]

scenario:credit_card/is_card_number_no_luhn/37828224631

  • 🟩 execution_time [-401.354ns; -401.117ns] or [-24.867%; -24.853%]
  • 🟩 throughput [+204920858.368op/s; +205057011.063op/s] or [+33.074%; +33.096%]

scenario:credit_card/is_card_number_no_luhn/378282246310005

  • 🟩 execution_time [-2.398µs; -2.254µs] or [-2.853%; -2.681%]
  • 🟩 throughput [+328080.653op/s; +349098.542op/s] or [+2.758%; +2.935%]

scenario:credit_card/is_card_number_no_luhn/37828224631000521389798

  • 🟩 execution_time [-10.581µs; -10.435µs] or [-9.449%; -9.318%]
  • 🟩 throughput [+918126.140op/s; +931716.083op/s] or [+10.281%; +10.433%]

scenario:redis/obfuscate_redis_string

  • 🟥 execution_time [+1.659µs; +2.134µs] or [+4.384%; +5.639%]

Candidate

Candidate benchmark details

Group 1

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
two way interface execution_time 16.954µs 21.721µs ± 12.221µs 17.108µs ± 0.050µs 17.189µs 50.861µs 52.587µs 112.761µs 559.11% 3.369 15.615 56.12% 0.864µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
two way interface execution_time [20.027µs; 23.415µs] or [-7.798%; +7.798%] None None None

Group 2

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
benching deserializing traces from msgpack to their internal representation execution_time 1.164µs 1.352µs ± 0.052µs 1.367µs ± 0.030µs 1.390µs 1.421µs 1.438µs 1.439µs 5.22% -1.019 1.679 3.86% 0.004µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
benching deserializing traces from msgpack to their internal representation execution_time [1.345µs; 1.359µs] or [-0.536%; +0.536%] None None None

Group 3

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_trace/test_trace execution_time 295.669ns 307.501ns ± 15.445ns 300.674ns ± 4.005ns 310.081ns 340.741ns 356.603ns 359.288ns 19.49% 1.698 2.024 5.01% 1.092ns 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_trace/test_trace execution_time [305.360ns; 309.641ns] or [-0.696%; +0.696%] None None None

Group 4

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... execution_time 618.451µs 619.049µs ± 0.404µs 618.990µs ± 0.189µs 619.211µs 619.470µs 619.942µs 622.910µs 0.63% 5.017 42.696 0.07% 0.029µs 1 200
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... throughput 1605368.867op/s 1615381.075op/s ± 1050.683op/s 1615535.245op/s ± 492.910op/s 1615929.662op/s 1616557.140op/s 1616766.064op/s 1616942.801op/s 0.09% -4.979 42.218 0.06% 74.295op/s 1 200
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて execution_time 466.288µs 467.682µs ± 1.250µs 467.565µs ± 0.354µs 467.940µs 468.563µs 469.133µs 483.504µs 3.41% 10.201 126.638 0.27% 0.088µs 1 200
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて throughput 2068235.441op/s 2138218.919op/s ± 5566.131op/s 2138740.189op/s ± 1620.112op/s 2140200.056op/s 2142312.561op/s 2143649.661op/s 2144595.878op/s 0.27% -10.004 123.335 0.26% 393.585op/s 1 200
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters execution_time 190.635µs 191.233µs ± 0.637µs 191.191µs ± 0.193µs 191.372µs 191.584µs 191.843µs 199.467µs 4.33% 10.882 138.154 0.33% 0.045µs 1 200
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters throughput 5013370.273op/s 5229281.789op/s ± 16814.491op/s 5230377.335op/s ± 5263.697op/s 5235931.405op/s 5240966.222op/s 5243550.521op/s 5245639.864op/s 0.29% -10.665 134.414 0.32% 1188.964op/s 1 200
normalization/normalize_service/normalize_service/[empty string] execution_time 46.744µs 47.232µs ± 0.166µs 47.241µs ± 0.109µs 47.336µs 47.504µs 47.572µs 47.792µs 1.17% 0.027 0.750 0.35% 0.012µs 1 200
normalization/normalize_service/normalize_service/[empty string] throughput 20924166.635op/s 21172253.234op/s ± 74448.938op/s 21168021.168op/s ± 48730.437op/s 21220315.975op/s 21281244.035op/s 21371181.871op/s 21393214.775op/s 1.06% 0.002 0.741 0.35% 5264.335op/s 1 200
normalization/normalize_service/normalize_service/test_ASCII execution_time 51.280µs 51.595µs ± 0.120µs 51.604µs ± 0.084µs 51.678µs 51.793µs 51.827µs 51.897µs 0.57% -0.114 -0.410 0.23% 0.008µs 1 200
normalization/normalize_service/normalize_service/test_ASCII throughput 19269064.732op/s 19381680.915op/s ± 45122.353op/s 19378215.363op/s ± 31691.130op/s 19412918.689op/s 19452595.676op/s 19492080.525op/s 19500952.064op/s 0.63% 0.125 -0.405 0.23% 3190.632op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... execution_time [618.993µs; 619.105µs] or [-0.009%; +0.009%] None None None
normalization/normalize_service/normalize_service/A0000000000000000000000000000000000000000000000000... throughput [1615235.460op/s; 1615526.689op/s] or [-0.009%; +0.009%] None None None
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて execution_time [467.509µs; 467.855µs] or [-0.037%; +0.037%] None None None
normalization/normalize_service/normalize_service/Data🐨dog🐶 繋がっ⛰てて throughput [2137447.507op/s; 2138990.331op/s] or [-0.036%; +0.036%] None None None
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters execution_time [191.145µs; 191.321µs] or [-0.046%; +0.046%] None None None
normalization/normalize_service/normalize_service/Test Conversion 0f Weird !@#$%^&**() Characters throughput [5226951.463op/s; 5231612.116op/s] or [-0.045%; +0.045%] None None None
normalization/normalize_service/normalize_service/[empty string] execution_time [47.209µs; 47.255µs] or [-0.049%; +0.049%] None None None
normalization/normalize_service/normalize_service/[empty string] throughput [21161935.327op/s; 21182571.140op/s] or [-0.049%; +0.049%] None None None
normalization/normalize_service/normalize_service/test_ASCII execution_time [51.579µs; 51.612µs] or [-0.032%; +0.032%] None None None
normalization/normalize_service/normalize_service/test_ASCII throughput [19375427.391op/s; 19387934.439op/s] or [-0.032%; +0.032%] None None None

Group 5

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
credit_card/is_card_number/ execution_time 1.212µs 1.212µs ± 0.000µs 1.212µs ± 0.000µs 1.212µs 1.213µs 1.213µs 1.214µs 0.16% 1.260 3.422 0.03% 0.000µs 1 200
credit_card/is_card_number/ throughput 823710971.724op/s 824965727.902op/s ± 240604.125op/s 824991315.489op/s ± 166728.450op/s 825148233.183op/s 825257460.844op/s 825353671.193op/s 825408738.945op/s 0.05% -1.256 3.404 0.03% 17013.281op/s 1 200
credit_card/is_card_number/ 3782-8224-6310-005 execution_time 110.355µs 114.338µs ± 1.417µs 114.323µs ± 0.807µs 115.111µs 116.641µs 117.727µs 121.256µs 6.06% 0.596 2.599 1.24% 0.100µs 1 200
credit_card/is_card_number/ 3782-8224-6310-005 throughput 8246982.120op/s 8747302.962op/s ± 107741.195op/s 8747119.312op/s ± 61496.812op/s 8811761.836op/s 8921893.949op/s 8984222.507op/s 9061680.491op/s 3.60% -0.445 2.127 1.23% 7618.453op/s 1 200
credit_card/is_card_number/ 378282246310005 execution_time 106.073µs 108.764µs ± 1.098µs 108.765µs ± 0.785µs 109.579µs 110.592µs 111.281µs 111.460µs 2.48% 0.097 -0.460 1.01% 0.078µs 1 200
credit_card/is_card_number/ 378282246310005 throughput 8971796.961op/s 9195160.802op/s ± 92736.589op/s 9194156.287op/s ± 66343.499op/s 9259277.224op/s 9343029.665op/s 9390629.429op/s 9427486.184op/s 2.54% -0.051 -0.474 1.01% 6557.467op/s 1 200
credit_card/is_card_number/37828224631 execution_time 1.212µs 1.214µs ± 0.003µs 1.213µs ± 0.001µs 1.215µs 1.216µs 1.216µs 1.247µs 2.81% 7.653 85.995 0.24% 0.000µs 1 200
credit_card/is_card_number/37828224631 throughput 801997153.815op/s 823808547.098op/s ± 1910912.147op/s 824547105.459op/s ± 758366.122op/s 824998226.662op/s 825230810.558op/s 825325293.399op/s 825365443.913op/s 0.10% -7.447 82.861 0.23% 135121.894op/s 1 200
credit_card/is_card_number/378282246310005 execution_time 101.705µs 105.473µs ± 1.025µs 105.534µs ± 0.668µs 106.128µs 107.009µs 107.904µs 109.000µs 3.28% -0.153 0.860 0.97% 0.072µs 1 200
credit_card/is_card_number/378282246310005 throughput 9174323.444op/s 9481997.199op/s ± 92333.058op/s 9475624.933op/s ± 59956.551op/s 9539957.410op/s 9637580.347op/s 9690010.618op/s 9832348.115op/s 3.76% 0.235 0.899 0.97% 6528.933op/s 1 200
credit_card/is_card_number/37828224631000521389798 execution_time 100.600µs 101.546µs ± 0.354µs 101.502µs ± 0.219µs 101.751µs 102.198µs 102.483µs 102.904µs 1.38% 0.468 0.810 0.35% 0.025µs 1 200
credit_card/is_card_number/37828224631000521389798 throughput 9717814.305op/s 9847833.984op/s ± 34323.574op/s 9852038.317op/s ± 21324.671op/s 9869774.312op/s 9894655.205op/s 9929195.585op/s 9940354.859op/s 0.90% -0.441 0.771 0.35% 2427.043op/s 1 200
credit_card/is_card_number/x371413321323331 execution_time 20.146µs 21.678µs ± 0.575µs 21.741µs ± 0.429µs 22.142µs 22.485µs 22.772µs 22.798µs 4.86% -0.301 -0.675 2.65% 0.041µs 1 200
credit_card/is_card_number/x371413321323331 throughput 43863845.112op/s 46162652.114op/s ± 1236677.016op/s 45995964.549op/s ± 909885.822op/s 46996177.094op/s 48278108.344op/s 49155428.853op/s 49636954.884op/s 7.92% 0.402 -0.560 2.67% 87446.270op/s 1 200
credit_card/is_card_number_no_luhn/ execution_time 1.212µs 1.212µs ± 0.000µs 1.212µs ± 0.000µs 1.212µs 1.213µs 1.213µs 1.214µs 0.16% 0.957 2.311 0.03% 0.000µs 1 200
credit_card/is_card_number_no_luhn/ throughput 823619835.138op/s 824922808.293op/s ± 265347.663op/s 824927575.059op/s ± 193723.410op/s 825137068.501op/s 825262662.881op/s 825366118.634op/s 825418899.091op/s 0.06% -0.954 2.296 0.03% 18762.913op/s 1 200
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 execution_time 90.088µs 91.617µs ± 0.470µs 91.626µs ± 0.257µs 91.880µs 92.328µs 92.934µs 93.281µs 1.81% 0.127 1.229 0.51% 0.033µs 1 200
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 throughput 10720353.156op/s 10915307.237op/s ± 55979.220op/s 10913875.347op/s ± 30659.393op/s 10945503.711op/s 11000758.161op/s 11037206.315op/s 11100312.413op/s 1.71% -0.078 1.201 0.51% 3958.329op/s 1 200
credit_card/is_card_number_no_luhn/ 378282246310005 execution_time 84.511µs 85.403µs ± 0.390µs 85.377µs ± 0.158µs 85.539µs 86.056µs 86.296µs 88.235µs 3.35% 2.041 13.112 0.46% 0.028µs 1 200
credit_card/is_card_number_no_luhn/ 378282246310005 throughput 11333386.351op/s 11709454.485op/s ± 53006.526op/s 11712791.242op/s ± 21634.020op/s 11733133.751op/s 11794900.361op/s 11818007.687op/s 11832824.254op/s 1.02% -1.896 11.942 0.45% 3748.127op/s 1 200
credit_card/is_card_number_no_luhn/37828224631 execution_time 1.212µs 1.213µs ± 0.001µs 1.213µs ± 0.000µs 1.213µs 1.213µs 1.215µs 1.219µs 0.52% 5.079 42.293 0.05% 0.000µs 1 200
credit_card/is_card_number_no_luhn/37828224631 throughput 820359893.468op/s 824574510.386op/s ± 443524.942op/s 824658850.300op/s ± 165960.188op/s 824790461.651op/s 825031745.423op/s 825239816.122op/s 825339597.757op/s 0.08% -5.049 41.915 0.05% 31361.949op/s 1 200
credit_card/is_card_number_no_luhn/378282246310005 execution_time 80.529µs 81.748µs ± 0.407µs 81.704µs ± 0.231µs 81.943µs 82.440µs 83.213µs 83.541µs 2.25% 1.226 3.335 0.50% 0.029µs 1 200
credit_card/is_card_number_no_luhn/378282246310005 throughput 11970194.799op/s 12232966.861op/s ± 60473.399op/s 12239324.797op/s ± 34664.546op/s 12273260.558op/s 12309966.604op/s 12338831.860op/s 12417869.172op/s 1.46% -1.169 3.169 0.49% 4276.115op/s 1 200
credit_card/is_card_number_no_luhn/37828224631000521389798 execution_time 100.613µs 101.471µs ± 0.471µs 101.436µs ± 0.260µs 101.694µs 102.186µs 102.490µs 105.016µs 3.53% 2.450 15.469 0.46% 0.033µs 1 200
credit_card/is_card_number_no_luhn/37828224631000521389798 throughput 9522381.396op/s 9855237.433op/s ± 45263.514op/s 9858460.396op/s ± 25246.216op/s 9883673.164op/s 9915259.494op/s 9936129.002op/s 9939106.408op/s 0.82% -2.296 14.081 0.46% 3200.614op/s 1 200
credit_card/is_card_number_no_luhn/x371413321323331 execution_time 20.188µs 21.789µs ± 0.616µs 21.871µs ± 0.440µs 22.245µs 22.660µs 22.893µs 22.945µs 4.91% -0.397 -0.506 2.82% 0.044µs 1 200
credit_card/is_card_number_no_luhn/x371413321323331 throughput 43582500.489op/s 45931427.608op/s ± 1314675.687op/s 45722921.451op/s ± 928752.567op/s 46940386.147op/s 48563958.767op/s 49294178.343op/s 49533635.438op/s 8.33% 0.513 -0.352 2.86% 92961.609op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
credit_card/is_card_number/ execution_time [1.212µs; 1.212µs] or [-0.004%; +0.004%] None None None
credit_card/is_card_number/ throughput [824932382.484op/s; 824999073.319op/s] or [-0.004%; +0.004%] None None None
credit_card/is_card_number/ 3782-8224-6310-005 execution_time [114.142µs; 114.535µs] or [-0.172%; +0.172%] None None None
credit_card/is_card_number/ 3782-8224-6310-005 throughput [8732371.069op/s; 8762234.855op/s] or [-0.171%; +0.171%] None None None
credit_card/is_card_number/ 378282246310005 execution_time [108.612µs; 108.916µs] or [-0.140%; +0.140%] None None None
credit_card/is_card_number/ 378282246310005 throughput [9182308.402op/s; 9208013.201op/s] or [-0.140%; +0.140%] None None None
credit_card/is_card_number/37828224631 execution_time [1.213µs; 1.214µs] or [-0.033%; +0.033%] None None None
credit_card/is_card_number/37828224631 throughput [823543713.053op/s; 824073381.144op/s] or [-0.032%; +0.032%] None None None
credit_card/is_card_number/378282246310005 execution_time [105.331µs; 105.615µs] or [-0.135%; +0.135%] None None None
credit_card/is_card_number/378282246310005 throughput [9469200.725op/s; 9494793.673op/s] or [-0.135%; +0.135%] None None None
credit_card/is_card_number/37828224631000521389798 execution_time [101.497µs; 101.596µs] or [-0.048%; +0.048%] None None None
credit_card/is_card_number/37828224631000521389798 throughput [9843077.067op/s; 9852590.902op/s] or [-0.048%; +0.048%] None None None
credit_card/is_card_number/x371413321323331 execution_time [21.598µs; 21.758µs] or [-0.368%; +0.368%] None None None
credit_card/is_card_number/x371413321323331 throughput [45991260.573op/s; 46334043.654op/s] or [-0.371%; +0.371%] None None None
credit_card/is_card_number_no_luhn/ execution_time [1.212µs; 1.212µs] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/ throughput [824886033.659op/s; 824959582.927op/s] or [-0.004%; +0.004%] None None None
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 execution_time [91.552µs; 91.682µs] or [-0.071%; +0.071%] None None None
credit_card/is_card_number_no_luhn/ 3782-8224-6310-005 throughput [10907549.055op/s; 10923065.418op/s] or [-0.071%; +0.071%] None None None
credit_card/is_card_number_no_luhn/ 378282246310005 execution_time [85.349µs; 85.457µs] or [-0.063%; +0.063%] None None None
credit_card/is_card_number_no_luhn/ 378282246310005 throughput [11702108.290op/s; 11716800.679op/s] or [-0.063%; +0.063%] None None None
credit_card/is_card_number_no_luhn/37828224631 execution_time [1.213µs; 1.213µs] or [-0.007%; +0.007%] None None None
credit_card/is_card_number_no_luhn/37828224631 throughput [824513042.095op/s; 824635978.677op/s] or [-0.007%; +0.007%] None None None
credit_card/is_card_number_no_luhn/378282246310005 execution_time [81.692µs; 81.805µs] or [-0.069%; +0.069%] None None None
credit_card/is_card_number_no_luhn/378282246310005 throughput [12224585.829op/s; 12241347.892op/s] or [-0.069%; +0.069%] None None None
credit_card/is_card_number_no_luhn/37828224631000521389798 execution_time [101.406µs; 101.536µs] or [-0.064%; +0.064%] None None None
credit_card/is_card_number_no_luhn/37828224631000521389798 throughput [9848964.346op/s; 9861510.521op/s] or [-0.064%; +0.064%] None None None
credit_card/is_card_number_no_luhn/x371413321323331 execution_time [21.704µs; 21.874µs] or [-0.392%; +0.392%] None None None
credit_card/is_card_number_no_luhn/x371413321323331 throughput [45749226.202op/s; 46113629.015op/s] or [-0.397%; +0.397%] None None None

Group 6

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... execution_time 295.738µs 301.775µs ± 1.513µs 302.074µs ± 0.936µs 302.915µs 303.724µs 304.147µs 304.726µs 0.88% -0.900 0.846 0.50% 0.107µs 1 200
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... throughput 3281631.433op/s 3313811.786op/s ± 16689.837op/s 3310445.891op/s ± 10226.389op/s 3323350.563op/s 3346176.371op/s 3358371.269op/s 3381373.890op/s 2.14% 0.931 0.944 0.50% 1180.150op/s 1 200
normalization/normalize_name/normalize_name/bad-name execution_time 28.529µs 28.785µs ± 0.098µs 28.800µs ± 0.064µs 28.858µs 28.923µs 28.950µs 28.982µs 0.63% -0.509 -0.369 0.34% 0.007µs 1 200
normalization/normalize_name/normalize_name/bad-name throughput 34504117.212op/s 34741195.970op/s ± 117961.941op/s 34722444.622op/s ± 77868.312op/s 34817185.066op/s 34956256.155op/s 35042196.793op/s 35052517.519op/s 0.95% 0.523 -0.354 0.34% 8341.169op/s 1 200
normalization/normalize_name/normalize_name/good execution_time 16.501µs 16.585µs ± 0.113µs 16.540µs ± 0.032µs 16.565µs 16.815µs 16.848µs 16.875µs 2.03% 1.327 0.048 0.68% 0.008µs 1 200
normalization/normalize_name/normalize_name/good throughput 59257533.753op/s 60296869.193op/s ± 407030.193op/s 60458389.254op/s ± 116165.622op/s 60575551.298op/s 60594225.104op/s 60598223.046op/s 60602894.311op/s 0.24% -1.321 0.033 0.67% 28781.381op/s 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... execution_time [301.565µs; 301.985µs] or [-0.069%; +0.069%] None None None
normalization/normalize_name/normalize_name/Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Lo... throughput [3311498.735op/s; 3316124.837op/s] or [-0.070%; +0.070%] None None None
normalization/normalize_name/normalize_name/bad-name execution_time [28.771µs; 28.798µs] or [-0.047%; +0.047%] None None None
normalization/normalize_name/normalize_name/bad-name throughput [34724847.579op/s; 34757544.361op/s] or [-0.047%; +0.047%] None None None
normalization/normalize_name/normalize_name/good execution_time [16.570µs; 16.601µs] or [-0.094%; +0.094%] None None None
normalization/normalize_name/normalize_name/good throughput [60240458.723op/s; 60353279.663op/s] or [-0.094%; +0.094%] None None None

Group 7

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
tags/replace_trace_tags execution_time 2.683µs 2.731µs ± 0.016µs 2.730µs ± 0.010µs 2.743µs 2.750µs 2.754µs 2.764µs 1.24% -0.813 0.610 0.57% 0.001µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
tags/replace_trace_tags execution_time [2.729µs; 2.733µs] or [-0.079%; +0.079%] None None None

Group 8

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
redis/obfuscate_redis_string execution_time 39.118µs 39.738µs ± 1.162µs 39.199µs ± 0.033µs 39.279µs 42.244µs 42.301µs 42.824µs 9.25% 1.700 0.929 2.92% 0.082µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
redis/obfuscate_redis_string execution_time [39.577µs; 39.899µs] or [-0.405%; +0.405%] None None None

Group 9

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
sql/obfuscate_sql_string execution_time 75.207µs 75.532µs ± 0.182µs 75.525µs ± 0.078µs 75.604µs 75.710µs 75.933µs 77.341µs 2.40% 5.015 47.500 0.24% 0.013µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
sql/obfuscate_sql_string execution_time [75.507µs; 75.557µs] or [-0.033%; +0.033%] None None None

Group 10

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
benching string interning on wordpress profile execution_time 136.014µs 136.407µs ± 0.208µs 136.360µs ± 0.093µs 136.482µs 136.738µs 137.172µs 137.892µs 1.12% 3.039 16.025 0.15% 0.015µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
benching string interning on wordpress profile execution_time [136.378µs; 136.436µs] or [-0.021%; +0.021%] None None None

Group 11

cpu_model git_commit_sha git_commit_date git_branch
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz 01e7245 1725446843 bob/rate_limiter
scenario metric min mean ± sd median ± mad p75 p95 p99 max peak_to_median_ratio skewness kurtosis cv sem runs sample_size
write only interface execution_time 1.458µs 2.920µs ± 1.393µs 2.760µs ± 0.023µs 2.781µs 3.067µs 12.642µs 15.847µs 474.23% 7.966 63.581 47.60% 0.099µs 1 200
scenario metric 95% CI mean Shapiro-Wilk pvalue Ljung-Box pvalue (lag=1) Dip test pvalue
write only interface execution_time [2.727µs; 3.113µs] or [-6.613%; +6.613%] None None None

Baseline

Omitted due to size.

@bwoebi bwoebi force-pushed the bob/rate_limiter branch 2 times, most recently from b482de9 to 3b7b39a Compare August 1, 2024 00:31
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

ddcommon/src/rate_limiter.rs Outdated Show resolved Hide resolved
@@ -44,7 +44,7 @@ jobs:
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }} && rustup component add clippy
- name: Run clippy on ${{ matrix.platform }} ${{ matrix.rust_version }}
shell: bash
run: cargo clippy --all-targets --all-features -- -D warnings "$([ ${{ matrix.rust_version }} = 1.71.1 ] && echo -Aunknown-lints)"
run: cargo clippy --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.71.1 ] && echo -Aunknown-lints -Aclippy::cast_ref_to_mut)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this change in a separate PR?

since this has broader impact than just ddcommon, would be good to get review from others in the repo. also helps if we ever have to revert this PR, this seems like a reasonable change to not have tied to this rate limiter implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this only affects the 1.71.1 stable clippy. Sometimes clippy changes between versions, but we run clippy against nightly and stable. Sometimes these can be conflicting.
Had to be done in the past and seems necessary now.

pub trait Limiter {
/// Takes the limit per interval.
/// Returns false if the limit is exceeded, otherwise true.
fn inc(&self, limit: u32) -> bool;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to support passing in the rate limit and changing it dynamically at check time because if it is shared across processes and each process is using a different limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more about the scenario where a limit is changed - but gradually rolled out (e.g. webserver graceful restarted). It should gradually adapt to the new limit.
It's less about having two actively concurring limits for the same thing for a prolonged time, though that scenario also works.

ddcommon/src/rate_limiter.rs Show resolved Hide resolved
#[cfg_attr(miri, ignore)]
fn test_rate_limiter() {
let limiter = LocalLimiter::default();
// Two are allowed, then one more because a small amount of time passed since the first one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way for us to mock now? seems like this test will be flaky if we rely on execution time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't flaky as long as it runs within ~100ms (which really is plenty of time).
In fact this test was flaky because ... it was running faster than the precision of the timer allowed. Hence the test adds 100 µs in between calls.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Comment on lines 19 to 20
/// The implementation is a sliding window: every time the limiter is increased, the as much time as
/// has passed is also refilled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some words are missing.
Is this correct: The implementation is a sliding window: every time the limiter is increased, the amount of time that has passed is also refilled.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :-)

@bwoebi bwoebi merged commit 081589b into main Sep 4, 2024
40 checks passed
@bwoebi bwoebi deleted the bob/rate_limiter branch September 4, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants