Skip to content

Instantly share code, notes, and snippets.

@keynslug
Created August 23, 2023 15:36
Show Gist options
  • Save keynslug/c0393ab5189417df46dd48f745c90600 to your computer and use it in GitHub Desktop.
Save keynslug/c0393ab5189417df46dd48f745c90600 to your computer and use it in GitHub Desktop.
Perf comparison / release-52 (Orig) vs PR#11481 (Head)
> emqx_topicidx_bench:run(fixed).
Orig: [{memory,534},
{name,emqx_topic_index_r52},
{size,15},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,504},
{name,emqx_topic_index},
{size,15},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Fixed Topics
+ Head Match / Fixed Topics
+--------------------------------------------------------------------------+
|+ +++++**************x*+*x+ x x x x|
| +++++*************x +xx |
| ++++***********x*x x |
| +++++*********xx*x |
| ++++++********xx*x |
| + ++++********xxx |
| + ++++*+******xxx |
| ++++*+******xxx |
| ++++++*****xxxx |
| ++++++***x*xxx |
| + +++ ***x* xx |
| + +++ **xxx xx |
| +++ **xxx x |
| +++ **xxx x |
| +++ **xxx |
| +++ **xxx |
| ++ *xxxx |
| ++ *xxxx |
| ++ +xxx |
| ++ +xxx |
| + +xxx |
| + +xxx |
| + +xx |
| |___M_A____| |
| |___A____| |
+--------------------------------------------------------------------------+
Dataset: x N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 472.000
1st Qu. 483.000
Median: 485.000
3rd Qu. 490.000
Max: 592.000
Average: 487.385 [ -7.43200e-3] ( 486.245 ‥ 489.495)
Std. Dev: 10.5833 [ -0.354228] ( 6.98743 ‥ 20.7364)
Outliers: 1/9 = 10 (μ=487.378, σ=10.2291)
Outlier variance: 0.257921 (moderate)
------
Dataset: + N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 459.000
1st Qu. 474.000
Median: 479.000
3rd Qu. 484.000
Max: 506.000
Average: 479.455 [ 4.53200e-3] ( 478.380 ‥ 480.600)
Std. Dev: 8.03184 [ -3.09169e-2] ( 7.27407 ‥ 9.01186)
Outliers: 0/4 = 4 (μ=479.460, σ=8.00093)
Outlier variance: 0.170980 (moderate)
Difference at 95.0% confidence
-7.93000 ± 1.84134
-1.62705% ± 0.377801%
(Student's t, pooled s = 9.39461)
------
> emqx_topicidx_bench:run(fixed_rules).
Orig: [{memory,292},
{name,emqx_topic_index_r52},
{size,5},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,282},
{name,emqx_topic_index},
{size,5},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Fixed Rules
+ Head Match / Fixed Rules
+--------------------------------------------------------------------------+
|+++++++++++ xxxxxxxxxxx x x x|
|++++++++ + xxxxxxxxxx x |
|++++++++ xxxxxxxx |
|++++++++ xxxxxxx |
| +++++++ xxxxxx |
| +++++++ xxxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| ++++ xxxxx |
| ++++ xxxxx |
| ++++ xxx x |
| ++++ xxx x |
| ++++ xx x |
| ++++ xx x |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| ++++ xx |
| + ++ xx |
| + ++ xx |
| + ++ xx |
| + ++ xx |
| + ++ xx |
| + ++ xx |
| + ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| + x |
| + x |
| + x |
| |__MA____| |
| |_A_| |
+--------------------------------------------------------------------------+
Dataset: x N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 342.000
1st Qu. 348.000
Median: 350.000
3rd Qu. 354.000
Max: 539.000
Average: 353.315 [ -1.19300e-3] ( 351.835 ‥ 357.040)
Std. Dev: 15.7441 [ -1.11507] ( 7.34450 ‥ 33.2940)
Outliers: 0/13 = 13 (μ=353.314, σ=14.6290)
Outlier variance: 0.595360 (severe, the data set is probably unusable)
------
Dataset: + N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 295.000
1st Qu. 301.000
Median: 305.000
3rd Qu. 309.000
Max: 330.000
Average: 305.270 [ 6.65500e-4] ( 304.475 ‥ 306.135)
Std. Dev: 6.00980 [ -2.94116e-2] ( 5.31473 ‥ 7.05893)
Outliers: 0/3 = 3 (μ=305.271, σ=5.98039)
Outlier variance: 0.219337 (moderate)
Difference at 95.0% confidence
-48.0450 ± 2.33558
-13.5983% ± 0.661048%
(Student's t, pooled s = 11.9162)
------
> emqx_topicidx_bench:run(fixed_5k_rules).
Orig: [{memory,145417},
{name,emqx_topic_index_r52},
{size,5102},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,140917},
{name,emqx_topic_index},
{size,5102},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Fixed Rules (5000)
+ Head Match / Fixed Rules (5000)
+--------------------------------------------------------------------------+
|+ +++********x**x* xx+x x x|
| ++********x*x |
| +++*******xx |
| +++*******xx |
| +++******* |
| +++****** |
| + +****** |
| + +****xx |
| + +****xx |
| ++**x x |
| +**x x |
| **x |
| **x |
| x*x |
| x*x |
| x+x |
| |_____MA_______| |
| |__MA__| |
+--------------------------------------------------------------------------+
Dataset: x N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 753.000
1st Qu. 760.000
Median: 764.000
3rd Qu. 771.000
Max: 948.000
Average: 769.000 [ 2.35720e-2] ( 766.390 ‥ 776.280)
Std. Dev: 20.7423 [ -1.57615] ( 9.50289 ‥ 44.2322)
Outliers: 0/6 = 6 (μ=769.024, σ=19.1661)
Outlier variance: 0.209605 (moderate)
------
Dataset: + N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 736.000
1st Qu. 754.000
Median: 760.000
3rd Qu. 766.000
Max: 801.000
Average: 760.800 [ 1.05710e-2] ( 759.060 ‥ 762.820)
Std. Dev: 9.76388 [ -0.111561] ( 8.29906 ‥ 12.5140)
Outliers: 0/2 = 2 (μ=760.811, σ=9.65232)
Outlier variance: 5.65848e-2 (slight)
Difference at 95.0% confidence
-8.20000 ± 4.49339
-1.06632% ± 0.584315%
(Student's t, pooled s = 16.2107)
------
> emqx_topicidx_bench:run(fixed_15k).
Orig: [{memory,435909},
{name,emqx_topic_index_r52},
{size,15306},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,422409},
{name,emqx_topic_index},
{size,15306},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Fixed Topics (15000)
+ Head Match / Fixed Topics (15000)
+--------------------------------------------------------------------------+
| xxxxxxxxxxxx x + +x*++++++++++++++ + + x+|
| xxxxxxxxxxx x + *++++++++++++++ + |
| xxxxxxxxx x x ++++++++++ + |
| xxxxxx xx ++++++++++ + |
| xxxxx xx ++++++++ + |
| xxxxx xx +++ ++++ + |
| xxxx x ++ ++++ + |
| xxxx x + ++++ |
| xxxx x + ++ + |
| xxxx + ++ + |
| xxxx + ++ |
| xxx + |
||_____M_A______| |
| |_____MA_____| |
+--------------------------------------------------------------------------+
Dataset: x N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 949.000
1st Qu. 958.000
Median: 963.000
3rd Qu. 970.000
Max: 1153.00
Average: 967.240 [ -3.04130e-2] ( 964.530 ‥ 974.670)
Std. Dev: 21.6856 [ -1.80244] ( 10.0663 ‥ 42.8902)
Outliers: 0/4 = 4 (μ=967.210, σ=19.8832)
Outlier variance: 0.161017 (moderate)
------
Dataset: + N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 998.000
1st Qu. 1017.00
Median: 1026.00
3rd Qu. 1033.00
Max: 1155.00
Average: 1027.77 [ -2.74230e-2] ( 1025.13 ‥ 1032.66)
Std. Dev: 17.7297 [ -0.671734] ( 11.6645 ‥ 32.5120)
Outliers: 0/2 = 2 (μ=1027.74, σ=17.0579)
Outlier variance: 0.103647 (moderate)
Difference at 95.0% confidence
60.5300 ± 5.49012
6.25801% ± 0.567607%
(Student's t, pooled s = 19.8066)
------
> emqx_topicidx_bench:run(topics_only).
Orig: [{memory,14364},
{name,emqx_topic_index_r52},
{size,441},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,8040},
{name,emqx_topic_index},
{size,441},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Topics = Filters
+ Head Match / Topics = Filters
+--------------------------------------------------------------------------+
|++++++ xxxxxxx x|
|++++ xxxxxx |
|++++ xxxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|+++ xxxx |
| ++ xxxx |
| ++ xxxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ xx |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| |_A_| |
| A| |
+--------------------------------------------------------------------------+
Dataset: x N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 647.000
1st Qu. 654.000
Median: 658.000
3rd Qu. 663.000
Max: 845.000
Average: 660.185 [ -8.42400e-3] ( 658.815 ‥ 663.885)
Std. Dev: 15.1833 [ -1.15401] ( 7.28935 ‥ 32.5819)
Outliers: 0/6 = 6 (μ=660.177, σ=14.0293)
Outlier variance: 0.277578 (moderate)
------
Dataset: + N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 319.000
1st Qu. 325.000
Median: 329.000
3rd Qu. 332.000
Max: 353.000
Average: 329.245 [ 7.62350e-3] ( 328.510 ‥ 330.030)
Std. Dev: 5.45470 [ -1.83091e-2] ( 4.86191 ‥ 6.33621)
Outliers: 0/5 = 5 (μ=329.253, σ=5.43639)
Outlier variance: 0.166283 (moderate)
Difference at 95.0% confidence
-330.940 ± 2.23598
-50.1284% ± 0.338690%
(Student's t, pooled s = 11.4080)
------
> emqx_topicidx_bench:run(topics_rules).
Orig: [{memory,4902},
{name,emqx_topic_index_r52},
{size,147},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,2794},
{name,emqx_topic_index},
{size,147},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Topics = Rules
+ Head Match / Topics = Rules
+--------------------------------------------------------------------------+
|+++++ xxxxxxxx x x|
|+++++ xxxxxx x |
|++++ xxxxx |
|++++ xxxxx |
|++++ xxxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|++++ xxxx |
|+++ xxxx |
|+++ xxxx |
|+++ xxxx |
|+++ xxxx |
|+++ xxxx |
|+++ xxxx |
|+++ xxx |
|+++ xxx |
|+++ xxx |
|+++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xx |
| ++ xx |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| ++ x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| + |
| |_A__| |
| A| |
+--------------------------------------------------------------------------+
Dataset: x N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 472.000
1st Qu. 480.000
Median: 482.000
3rd Qu. 487.000
Max: 655.000
Average: 485.120 [ 6.85550e-3] ( 483.875 ‥ 488.630)
Std. Dev: 13.8414 [ -1.10621] ( 6.35170 ‥ 29.9589)
Outliers: 0/10 = 10 (μ=485.127, σ=12.7352)
Outlier variance: 0.375403 (moderate)
------
Dataset: + N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 235.000
1st Qu. 239.000
Median: 241.000
3rd Qu. 244.000
Max: 257.000
Average: 242.100 [ -1.77650e-3] ( 241.565 ‥ 242.705)
Std. Dev: 4.13224 [ -1.98386e-2] ( 3.67723 ‥ 4.71546)
Outliers: 0/9 = 9 (μ=242.098, σ=4.11240)
Outlier variance: 0.175822 (moderate)
Difference at 95.0% confidence
-243.020 ± 2.00198
-50.0948% ± 0.412677%
(Student's t, pooled s = 10.2142)
------
> emqx_topicidx_bench:run(topics_with_filters).
Orig: [{memory,14643},
{name,emqx_topic_index_r52},
{size,453},
{type,ordered_set},
{keypos,1},
{protection,public}]
Head: [{memory,8319},
{name,emqx_topic_index},
{size,453},
{type,ordered_set},
{keypos,1},
{protection,public}]
x Orig Match / Topics = Filters
+ Head Match / Topics = Filters
+--------------------------------------------------------------------------+
|+++++++++ xxxxxxxxxx x|
|+++++++++ xxxxxxx |
|+++++++++ xxxxxx |
|+++++++++ xxxxxx |
| +++++ + xxxxxx |
| +++++ + xxxxx |
| +++++ + xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxxx |
| +++++ xxx |
| +++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| ++++ xxx |
| +++ xxx |
| +++ xxx |
| +++ xxx |
| +++ xxx |
| +++ xxx |
| +++ xxx |
| ++ xxx |
| ++ xxx |
| ++ xxx |
| + xx |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| + x |
| |_MA_| |
| |A_| |
+--------------------------------------------------------------------------+
Dataset: x N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 951.000
1st Qu. 962.000
Median: 966.000
3rd Qu. 973.000
Max: 1169.00
Average: 969.350 [ -1.85750e-2] ( 967.655 ‥ 973.360)
Std. Dev: 17.5622 [ -1.00363] ( 9.90964 ‥ 35.7472)
Outliers: 0/9 = 9 (μ=969.331, σ=16.5585)
Outlier variance: 0.194998 (moderate)
------
Dataset: + N=200 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 638.000
1st Qu. 654.000
Median: 663.000
3rd Qu. 670.000
Max: 699.000
Average: 662.890 [ 2.16850e-3] ( 661.270 ‥ 664.545)
Std. Dev: 11.8427 [ -5.52750e-2] ( 10.7604 ‥ 13.1954)
Outliers: 0/3 = 3 (μ=662.892, σ=11.7874)
Outlier variance: 0.190209 (moderate)
Difference at 95.0% confidence
-306.460 ± 2.93568
-31.6150% ± 0.302850%
(Student's t, pooled s = 14.9780)
------
%%--------------------------------------------------------------------
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_topicidx_bench).
-compile([export_all, nowarn_export_all]).
-include_lib("stdlib/include/assert.hrl").
% -include_lib("proper/include/proper.hrl").
-define(FILTERS, [
<<"t/#">>,
<<"t/+/#">>,
<<"+/+/+/sub">>,
<<"dev/global/sensor">>,
<<"dev/+/sensor/#">>
]).
-define(FILTERGEN, [
{1, <<"t/+/+">>},
{1, <<"t/+/+/+">>},
{1000, [<<"dev">>, '+', fun() -> io_lib:format("~B", [next(dev)]) end, '#']},
{500, [<<"t">>, fun() -> io_lib:format("~3.10.0B", [next(fwd1)]) end, '#']},
{500, [<<"t">>, fun() -> io_lib:format("~3.10.0B", [next(fwd2)]) end, '+']},
{500, [<<"t">>, <<"fwd">>, fun() -> io_lib:format("~3.10.0B", [next(fwd1)]) end]},
{500, [<<"t">>, <<"fwd">>, fun() -> io_lib:format("~3.10.0B", [next(fwd2)]) end, '#']},
{100, [<<"$sys">>, '+', fun() -> io_lib:format("node~3.10.0B", [next(sys)]) end, '+']},
{500, ['+', <<"bridged">>, fun() -> io_lib:format("remote~3.10.0B", [next(plus1)]) end, '+']},
{500, [
'+',
<<"bridged">>,
fun() -> io_lib:format("remote~3.10.0B", [next(plus2)]) end,
<<"sub">>,
'+'
]},
{1000, [
<<"msg">>, <<"bridged">>, fun() -> io_lib:format("remote~3.10.0B", [next(msg)]) end, '#'
]}
]).
-define(NODES, [
node1,
node2,
node3
]).
-define(TOPICS, [
<<"dev/global/sensor/042">>,
<<"dev/global/sensor">>,
<<"dev/global">>,
<<"dev/local/temp">>,
<<"dev/local/humidity">>,
<<"dev/local">>,
<<"dev/local/0">>,
<<"dev/local/1">>,
<<"dev/local/2">>,
<<"dev/local/3">>,
<<"dev/local/4">>,
<<"dev/local/5">>,
<<"dev/local/6">>,
<<"dev/local/7">>,
<<"dev/local/8">>,
<<"dev/local/9">>,
<<"dev/local/sensor/temp/*">>,
<<"dev/local/sensor/temp/CPU/0">>,
<<"dev/local/sensor/temp/CPU/1">>,
<<"dev/local/sensor/temp/CPU/2">>,
<<"dev/local/sensor/temp/CPU/3">>,
<<"dev/local/sensor/temp/CPU/4">>,
<<"dev/local/sensor/temp/CPU/5">>,
<<"dev/local/sensor/temp/CPU/6">>,
<<"dev/local/sensor/temp/CPU/7">>,
<<"dev/local/sensor/temp/CPU/8">>,
<<"dev/local/sensor/temp/CPU/9">>,
<<"t/fwd/001">>,
<<"t/fwd/002">>,
<<"t/fwd/003">>,
<<"t/fwd/004">>,
<<"t/fwd/005">>,
<<"t/fwd/006">>,
<<"t/fwd/007">>,
<<"t/fwd/008">>,
<<"t/fwd/009">>,
<<"t/fwd/010">>,
<<"t/fwd/011">>,
<<"t/fwd/012">>,
<<"t/fwd/013">>,
<<"t/fwd/014">>,
<<"t/fwd/015">>,
<<"t/fwd/016">>,
<<"t/fwd/017">>,
<<"t/fwd/018">>,
<<"t/fwd/019">>,
<<"t/fwd/020">>,
<<"t/001">>,
<<"t/002">>,
<<"t/003">>,
<<"t/004">>,
<<"t/005">>,
<<"t/006">>,
<<"t/007">>,
<<"t/008">>,
<<"t/009">>,
<<"t/010">>,
<<"t/011">>,
<<"t/012">>,
<<"t/013">>,
<<"t/014">>,
<<"t/015">>,
<<"t/016">>,
<<"t/017">>,
<<"t/018">>,
<<"t/019">>,
<<"t/020">>,
<<"t/bridged/remote001/sub">>,
<<"t/bridged/remote002/sub">>,
<<"t/bridged/remote003/sub">>,
<<"t/bridged/remote004/sub">>,
<<"t/bridged/remote005/sub">>,
<<"t/bridged/remote006/sub">>,
<<"t/bridged/remote007/sub">>,
<<"t/bridged/remote008/sub">>,
<<"t/bridged/remote009/sub">>,
<<"t/bridged/remote010/sub">>,
<<"t/bridged/remote011/sub">>,
<<"t/bridged/remote012/sub">>,
<<"t/bridged/remote013/sub">>,
<<"t/bridged/remote014/sub">>,
<<"t/bridged/remote015/sub">>,
<<"t/bridged/remote016/sub">>,
<<"t/bridged/remote017/sub">>,
<<"t/bridged/remote018/sub">>,
<<"t/bridged/remote019/sub">>,
<<"t/bridged/remote020/sub">>,
<<"msg/bridged/remote001/sub">>,
<<"msg/bridged/remote002/sub">>,
<<"msg/bridged/remote003/sub">>,
<<"msg/bridged/remote004/sub">>,
<<"msg/bridged/remote005/sub">>,
<<"msg/bridged/remote006/sub">>,
<<"msg/bridged/remote007/sub">>,
<<"msg/bridged/remote008/sub">>,
<<"msg/bridged/remote009/sub">>,
<<"msg/bridged/remote010/sub">>,
<<"msg/bridged/remote011/sub">>,
<<"msg/bridged/remote012/sub">>,
<<"msg/bridged/remote013/sub">>,
<<"msg/bridged/remote014/sub">>,
<<"msg/bridged/remote015/sub">>,
<<"msg/bridged/remote016/sub">>,
<<"msg/bridged/remote017/sub">>,
<<"msg/bridged/remote018/sub">>,
<<"msg/bridged/remote019/sub">>,
<<"msg/bridged/remote020/sub">>,
<<"msg/bridged/remote001/sub/01">>,
<<"msg/bridged/remote002/sub/02">>,
<<"msg/bridged/remote003/sub/03">>,
<<"msg/bridged/remote004/sub/04">>,
<<"msg/bridged/remote005/sub/05">>,
<<"msg/bridged/remote006/sub/06">>,
<<"msg/bridged/remote007/sub/07">>,
<<"msg/bridged/remote008/sub/08">>,
<<"msg/bridged/remote009/sub/09">>,
<<"msg/bridged/remote010/sub/10">>,
<<"msg/bridged/remote011/sub/10">>,
<<"msg/bridged/remote012/sub/10">>,
<<"msg/bridged/remote013/sub/10">>,
<<"msg/bridged/remote014/sub/10">>,
<<"msg/bridged/remote015/sub/10">>,
<<"msg/bridged/remote016/sub/10">>,
<<"msg/bridged/remote017/sub/10">>,
<<"msg/bridged/remote018/sub/10">>,
<<"msg/bridged/remote019/sub/10">>,
<<"msg/bridged/remote020/sub/10">>,
<<"$sys/broker/node001/sub">>,
<<"$sys/broker/node002/sub">>,
<<"$sys/broker/node003/sub">>,
<<"$sys/broker/node004/sub">>,
<<"$sys/broker/node005/sub">>,
<<"$sys/broker/node006/sub">>,
<<"$sys/broker/node007/sub">>,
<<"$sys/broker/node008/sub">>,
<<"$sys/broker/node009/sub">>,
<<"$sys/broker/node010/sub">>,
<<"$sys/broker/node011/sub">>,
<<"$sys/broker/node012/sub">>,
<<"$sys/broker/node013/sub">>,
<<"$sys/broker/node014/sub">>,
<<"$sys/broker/node015/sub">>,
<<"$sys/broker/node016/sub">>,
<<"$sys/broker/node017/sub">>,
<<"$sys/broker/node018/sub">>,
<<"$sys/broker/node019/sub">>,
<<"$sys/broker/node020/sub">>
]).
prepare(Filters, Topics) ->
TabOrig = init(orig, Filters),
TabHead = init(head, Filters),
_ = ?assertEqual(
[[topic(orig, M) || M <- lists:sort(match_orig(T, TabOrig))] || T <- Topics],
[[topic(head, M) || M <- lists:sort(match_head(T, TabHead))] || T <- Topics]
),
{TabOrig, TabHead}.
run(Alias) when is_atom(Alias) ->
run(workload(Alias));
run(Workload = #{name := Name, entries := Entries, matches := Matches}) ->
Samples = maps:get(samples, Workload, 200),
run(Name, Entries, Matches, Samples).
workload(fixed) ->
#{
name => "Fixed Topics",
entries => cartesian(?FILTERS, ?NODES),
matches => ?TOPICS
};
workload(fixed_rules) ->
#{
name => "Fixed Rules",
entries => numbered(?FILTERS),
matches => ?TOPICS
};
workload(fixed_15k) ->
#{
name => "Fixed Topics (15000)",
entries => cartesian(gen(?FILTERGEN), ?NODES),
matches => ?TOPICS,
samples => 100
};
workload(fixed_5k_rules) ->
#{
name => "Fixed Rules (5000)",
entries => numbered(gen(?FILTERGEN)),
matches => ?TOPICS,
samples => 100
};
workload(topics_only) ->
#{
name => "Topics = Filters",
entries => cartesian(?TOPICS, ?NODES),
matches => ?TOPICS
};
workload(topics_rules) ->
#{
name => "Topics = Rules",
entries => numbered(?TOPICS),
matches => ?TOPICS
};
workload(topics_with_filters) ->
#{
name => "Topics = Filters",
entries => cartesian(?FILTERS ++ ?TOPICS, ?NODES),
matches => ?TOPICS
}.
run(Name, Entries, Topics, NSamples) ->
{TabOrig, TabHead} = prepare(Entries, Topics),
io:format("Orig: ~p~n", [ets:info(TabOrig)]),
io:format("Head: ~p~n", [ets:info(TabHead)]),
ROrig = eministat:s(
"Orig Match / " ++ Name,
fun() -> sample_orig(Topics, TabOrig) end,
NSamples
),
RHead = eministat:s(
"Head Match / " ++ Name,
fun() -> sample_head(Topics, TabHead) end,
NSamples
),
eministat:x(95.0, ROrig, RHead).
init(head, Entries) ->
Tab = emqx_topic_index:new(),
_ = [emqx_topic_index:insert(F, ID, [], Tab) || {F, ID} <- Entries],
Tab;
init(orig, Entries) ->
Tab = emqx_topic_index_r52:new(),
_ = [emqx_topic_index_r52:insert(F, ID, [], Tab) || {F, ID} <- Entries],
Tab.
-compile({inline, match_orig/2}).
match_orig(Topic, Tab) ->
emqx_topic_index_r52:matches(Topic, Tab, []).
-compile({inline, match_head/2}).
match_head(Topic, Tab) ->
emqx_topic_index:matches(Topic, Tab, []).
sample_orig(Topics, Tab) ->
lists:foreach(fun(T) -> match_orig(T, Tab) end, Topics).
sample_head(Topics, Tab) ->
lists:foreach(fun(T) -> match_head(T, Tab) end, Topics).
topic(orig, Match) ->
emqx_topic_index_r52:get_topic(Match);
topic(head, Match) ->
emqx_topic_index:get_topic(Match).
filters() ->
?FILTERS.
topics() ->
?TOPICS.
cartesian(A, B) ->
[{X, Y} || X <- A, Y <- B].
numbered(A) ->
lists:zip(A, lists:seq(1, length(A))).
%%
gen(Gens) when is_list(Gens) ->
Tab = ets:new(?MODULE, [set]),
_ = put({?MODULE, gentable}, Tab),
Result = lists:flatmap(fun({N, Gen}) -> gen(N, Gen) end, Gens),
_ = ets:delete(Tab),
Result.
gen(N, Generator) when is_integer(N) ->
[emit(Generator) || _ <- lists:seq(1, N)].
emit(Topic) when is_binary(Topic) ->
Topic;
emit(Topic) when is_list(Topic) ->
emqx_topic:join(
lists:map(
fun
(F) when is_function(F) -> F();
(W) when is_binary(W) -> W;
(W) when is_atom(W) -> W
end,
Topic
)
).
next(CounterName) ->
ets:update_counter(get({?MODULE, gentable}), CounterName, {2, 1}, {CounterName, 0}).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment