tonarino / actor

A minimalist actor framework aiming for high performance and simplicity.
MIT License
40 stars 6 forks source link

Add an experimental pub-sub API #67

Closed bschwind closed 2 years ago

bschwind commented 2 years ago

This is just to get a discussion going, there are many obvious flaws with this approach, but it has the start of something good. Let's iterate on it! It feels like a decent API to start with.

bschwind commented 2 years ago

@strohel good idea! I moved the subscribe() function to Context and I think that works nicely. Take a look at the example usage and let me know what you think.

strohel commented 2 years ago

@bschwind this is coming out really nicely!

If you don't mind waiting a bit, I'll spend some time playing with the API and TODOs in the code to see if I can iterate this further. We can set a "timeout" for this to start of the next week, and just go ahead with more or less the current form by the time if there's no development.

strohel commented 2 years ago

Benchmark results for https://github.com/tonarino/actor/commit/90089c15e39bc366f66a6fbb320ade5c40e15abd (RwLock)

Thinkpad T480 4 Intel cores:

publish/1 publishers 10 subscribers
                        time:   [20.233 us 20.472 us 20.730 us]
                        thrpt:  [48.238 Kelem/s 48.847 Kelem/s 49.425 Kelem/s]
                 change:
                        time:   [-2.8148% -1.4032% -0.0071%] (p = 0.06 > 0.05)
                        thrpt:  [+0.0071% +1.4232% +2.8963%]
                        No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
publish/2 publishers 10 subscribers
                        time:   [35.620 us 36.114 us 36.652 us]
                        thrpt:  [27.284 Kelem/s 27.690 Kelem/s 28.074 Kelem/s]
                 change:
                        time:   [-32.864% -31.967% -30.928%] (p = 0.00 < 0.05)
                        thrpt:  [+44.777% +46.988% +48.952%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
publish/10 publishers 10 subscribers
                        time:   [13.782 us 14.184 us 14.577 us]
                        thrpt:  [68.602 Kelem/s 70.503 Kelem/s 72.561 Kelem/s]
                 change:
                        time:   [-94.001% -93.697% -93.410%] (p = 0.00 < 0.05)
                        thrpt:  [+1417.4% +1486.4% +1566.9%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  2 (2.00%) high severe
publish/1 publishers 100 subscribers
                        time:   [237.29 us 238.86 us 240.37 us]
                        thrpt:  [4.1602 Kelem/s 4.1865 Kelem/s 4.2142 Kelem/s]
                 change:
                        time:   [-2.2219% -1.2377% -0.2828%] (p = 0.02 < 0.05)
                        thrpt:  [+0.2836% +1.2533% +2.2724%]
                        Change within noise threshold.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) low mild
  1 (1.00%) high mild
publish/2 publishers 100 subscribers
                        time:   [379.46 us 383.71 us 388.60 us]
                        thrpt:  [2.5734 Kelem/s 2.6062 Kelem/s 2.6353 Kelem/s]
                 change:
                        time:   [-22.200% -20.768% -19.282%] (p = 0.00 < 0.05)
                        thrpt:  [+23.887% +26.211% +28.535%]
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
publish/10 publishers 100 subscribers
                        time:   [1.3161 ms 1.3673 ms 1.4093 ms]
                        thrpt:  [709.56  elem/s 731.35  elem/s 759.84  elem/s]
                 change:
                        time:   [-48.118% -43.801% -39.608%] (p = 0.00 < 0.05)
                        thrpt:  [+65.586% +77.938% +92.744%]
                        Performance has improved.

Apple MacBook Pro 2021 10-core M1 Pro

publish/1 publishers 10 subscribers                        
                        time:   [4.9240 us 5.3191 us 5.8158 us]
                        thrpt:  [171.95 Kelem/s 188.00 Kelem/s 203.09 Kelem/s]
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) low mild
  1 (1.00%) high mild
  5 (5.00%) high severe
Benchmarking publish/2 publishers 10 subscribers: Collecting 100 samples in estimated 5.0471                                                                                              publish/2 publishers 10 subscribers                        
                        time:   [18.367 us 19.405 us 20.391 us]
                        thrpt:  [49.042 Kelem/s 51.533 Kelem/s 54.445 Kelem/s]
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) low mild
  1 (1.00%) high mild
Benchmarking publish/10 publishers 10 subscribers: Collecting 100 samples in estimated 5.0423                                                                                             publish/10 publishers 10 subscribers                        
                        time:   [111.58 us 115.57 us 120.38 us]
                        thrpt:  [8.3072 Kelem/s 8.6524 Kelem/s 8.9619 Kelem/s]
Found 9 outliers among 100 measurements (9.00%)
  5 (5.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe
Benchmarking publish/1 publishers 100 subscribers: Collecting 100 samples in estimated 5.6701                                                                                             publish/1 publishers 100 subscribers                        
                        time:   [128.32 us 140.51 us 153.48 us]
                        thrpt:  [6.5156 Kelem/s 7.1170 Kelem/s 7.7931 Kelem/s]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low mild
  7 (7.00%) high mild
Benchmarking publish/2 publishers 100 subscribers: Collecting 100 samples in estimated 5.5443                                                                                             publish/2 publishers 100 subscribers                        
                        time:   [141.33 us 171.77 us 204.92 us]
                        thrpt:  [4.8799 Kelem/s 5.8218 Kelem/s 7.0755 Kelem/s]
Found 14 outliers among 100 measurements (14.00%)
  6 (6.00%) high mild
  8 (8.00%) high severe
Benchmarking publish/10 publishers 100 subscribers: Collecting 100 samples in estimated 5.673                                                                                             publish/10 publishers 100 subscribers                        
                        time:   [1.0031 ms 1.1075 ms 1.2075 ms]
                        thrpt:  [828.14  elem/s 902.96  elem/s 996.92  elem/s]
Found 21 outliers among 100 measurements (21.00%)
  8 (8.00%) low severe
  2 (2.00%) low mild
  4 (4.00%) high mild
  7 (7.00%) high severe

dev-annex 8-core AMD Threadripper

publish/1 publishers 10 subscribers                                                                             
                        time:   [6.3256 us 6.4633 us 6.6055 us]
                        thrpt:  [151.39 Kelem/s 154.72 Kelem/s 158.09 Kelem/s]
publish/2 publishers 10 subscribers                                                                             
                        time:   [9.1439 us 9.2688 us 9.3967 us]
                        thrpt:  [106.42 Kelem/s 107.89 Kelem/s 109.36 Kelem/s]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
publish/10 publishers 10 subscribers                                                                             
                        time:   [3.1484 us 3.1792 us 3.2111 us]
                        thrpt:  [311.42 Kelem/s 314.55 Kelem/s 317.62 Kelem/s]
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  2 (2.00%) high severe
publish/1 publishers 100 subscribers                                                                            
                        time:   [61.651 us 62.004 us 62.379 us]
                        thrpt:  [16.031 Kelem/s 16.128 Kelem/s 16.220 Kelem/s]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
publish/2 publishers 100 subscribers                                                                             
                        time:   [88.821 us 89.260 us 89.852 us]
                        thrpt:  [11.129 Kelem/s 11.203 Kelem/s 11.259 Kelem/s]
Found 11 outliers among 100 measurements (11.00%)
  1 (1.00%) high mild
  10 (10.00%) high severe
publish/10 publishers 100 subscribers                                                                             
                        time:   [309.70 us 311.44 us 312.88 us]
                        thrpt:  [3.1961 Kelem/s 3.2109 Kelem/s 3.2289 Kelem/s]
Found 8 outliers among 100 measurements (8.00%)
  8 (8.00%) low mild