#### Pre-Submission Checklist - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [x] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [x] Small bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: - [ ] PR should be backported to stable branches - [x] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description This PR to fix a calculation error on the latency standard deviation
test with random values from 1-30 ``` total[1726000000]value[3] count[2097152] std[8.654594] avg[15.541001] est[14.098082] total[1727000000]value[2] count[2097152] std[8.654230] avg[15.542887] est[16.070623] total[1728000000]value[2] count[2097152] std[8.655254] avg[15.546928] est[13.154167] ``` test with random values 1-500 ``` total[1056000000]value[373] count[2097152] std[144.397552] avg[249.993790] est[297.913574] total[1057000000]value[118] count[2097152] std[144.369400] avg[250.121262] est[222.419662] total[1058000000]value[431] count[2097152] std[144.314056] avg[250.138077] est[295.765625] ```
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/1236
-- Commit Summary --
* dispatcher: latency fix stdev calculation
-- File Changes --
M src/modules/dispatcher/dispatch.c (29) M src/modules/dispatcher/dispatch.h (2)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/1236.patch https://github.com/kamailio/kamailio/pull/1236.diff
Just some extra comments and tests
I tested the weighted std and avg again, with a scenario where the random generator is starting at max=30 increments over time up to max=300 and decrement back to 30 to see how long it takes to adjust. 2 periods of 2097152 samples seems to be enough to get close.
I think this weight is making sense for a server running over a long period of time. But we could adjust the period based on ping interval to make sure it is matching clear time period.
The stdev in the middle of the scenario at max 300 is accurate 86.74 in libre office ``` total[56623104]max[300] M2[15362844409.015831] count[2097152] std[85.589592] avg[148.497940] est[186.914322] ```
``` total[2097152]max[30] M2[157100024.339350] count[2097152] std[8.655124] avg[15.495893] est[13.079656] total[4194304]max[60] M2[565161279.098511] count[2097152] std[16.416151] avg[24.987877] est[27.263668] total[6291456]max[60] M2[619712983.957470] count[2097152] std[17.190182] avg[28.423359] est[29.659512] total[8388608]max[60] M2[627188475.025724] count[2097152] std[17.293550] avg[29.725079] est[32.875008] total[10485760]max[90] M2[1247094770.763514] count[2097152] std[24.385681] avg[39.690018] est[45.258430] total[12582912]max[90] M2[1369149290.866558] count[2097152] std[25.551155] avg[43.338192] est[55.149673] total[14680064]max[90] M2[1399719270.525143] count[2097152] std[25.834831] avg[44.726627] est[47.590252] total[16777216]max[120] M2[2226973264.366464] count[2097152] std[32.586872] avg[54.664543] est[61.240814] total[18874368]max[120] M2[2426866858.845158] count[2097152] std[34.017948] avg[58.319107] est[67.435730] total[20971520]max[120] M2[2485716268.964881] count[2097152] std[34.427933] avg[59.637623] est[48.287968] total[23068672]max[150] M2[3523236730.424239] count[2097152] std[40.987938] avg[69.647438] est[80.191017] total[25165824]max[150] M2[3795763992.445277] count[2097152] std[42.543652] avg[73.368950] est[72.679794] total[27262976]max[150] M2[3886770781.855125] count[2097152] std[43.050640] avg[74.759964] est[70.232475] total[29360128]max[180] M2[5131618327.571171] count[2097152] std[49.466629] avg[84.692070] est[96.479042] total[31457280]max[180] M2[5484142140.309916] count[2097152] std[51.137501] avg[88.429367] est[87.843102] total[33554432]max[180] M2[5597876661.386850] count[2097152] std[51.665047] avg[89.803963] est[109.757233] total[35651584]max[210] M2[7053724001.055486] count[2097152] std[57.995510] avg[99.741013] est[91.987564] total[37748736]max[210] M2[7479776962.029222] count[2097152] std[59.721329] avg[103.352173] est[97.751457] total[39845888]max[210] M2[7630976936.031951] count[2097152] std[60.321930] avg[104.694923] est[115.147377] total[41943040]max[240] M2[9292088622.916683] count[2097152] std[66.564369] avg[114.621590] est[150.303802] total[44040192]max[240] M2[9796104291.010365] count[2097152] std[68.345802] avg[118.272659] est[122.886292] total[46137344]max[240] M2[9965937966.086864] count[2097152] std[68.935707] avg[119.582924] est[93.705055] total[48234496]max[270] M2[11848203838.922304] count[2097152] std[75.164261] avg[129.532562] est[144.145126] total[50331648]max[270] M2[12425804190.196043] count[2097152] std[76.974594] avg[133.170563] est[127.568375] total[52428800]max[270] M2[12618113837.423813] count[2097152] std[77.567963] avg[134.508347] est[132.567368] total[54525952]max[300] M2[14713927465.674479] count[2097152] std[83.762466] avg[144.738953] est[157.351410] total[56623104]max[300] M2[15362844409.015831] count[2097152] std[85.589592] avg[148.497940] est[186.914322] total[58720256]max[300] M2[15597086896.549715] count[2097152] std[86.239632] avg[149.828369] est[134.888901] total[60817408]max[270] M2[13897060743.879736] count[2097152] std[81.404167] avg[140.986145] est[148.230011] total[62914560]max[270] M2[13179605332.005194] count[2097152] std[79.275017] avg[137.667099] est[147.819626] total[65011712]max[270] M2[12904876783.172298] count[2097152] std[78.444427] avg[136.416397] est[174.410904] total[67108864]max[240] M2[11234667410.652538] count[2097152] std[73.192276] avg[126.221443] est[116.936584] total[69206016]max[240] M2[10506238432.030697] count[2097152] std[70.779709] avg[122.688011] est[147.278595] total[71303168]max[240] M2[10232558486.513565] count[2097152] std[69.851746] avg[121.319862] est[135.017303] total[73400320]max[210] M2[8753355360.939997] count[2097152] std[64.605934] avg[111.340347] est[102.771973] total[75497472]max[210] M2[8109358941.663550] count[2097152] std[62.183964] avg[107.595718] est[103.639900] total[77594624]max[210] M2[7858572277.892706] count[2097152] std[61.214874] avg[106.287216] est[121.709717] total[79691776]max[180] M2[6591117074.132572] count[2097152] std[56.061493] avg[96.341568] est[85.318893] total[81788928]max[180] M2[6022946657.180739] count[2097152] std[53.590729] avg[92.621536] est[70.211670] total[83886080]max[180] M2[5803221389.644814] count[2097152] std[52.604115] avg[91.284225] est[91.405876] total[85983232]max[150] M2[4742030532.232808] count[2097152] std[47.551838] avg[81.352226] est[65.601341] total[88080384]max[150] M2[4247261369.886361] count[2097152] std[45.002811] avg[77.583412] est[58.726521] total[90177536]max[150] M2[4050211394.232083] count[2097152] std[43.946468] avg[76.272026] est[94.734283] total[92274688]max[120] M2[3200787916.367090] count[2097152] std[39.067318] avg[66.359764] est[59.015381] total[94371840]max[120] M2[2785142322.233555] count[2097152] std[36.442558] avg[62.637939] est[62.011288] total[96468992]max[120] M2[2617178115.333484] count[2097152] std[35.326595] avg[61.309391] est[61.678368] total[98566144]max[90] M2[1981088219.305755] count[2097152] std[30.735271] avg[51.331150] est[43.893597] total[100663296]max[90] M2[1640345108.679696] count[2097152] std[27.967443] avg[47.665287] est[45.548306] total[102760448]max[90] M2[1500853910.913404] count[2097152] std[26.751883] avg[46.296799] est[48.260040] total[104857600]max[60] M2[1071488249.817324] count[2097152] std[22.603664] avg[36.338905] est[29.824390] total[106954752]max[60] M2[808602879.222455] count[2097152] std[19.635990] avg[32.646908] est[26.610825] total[109051904]max[60] M2[697691376.099365] count[2097152] std[18.239664] avg[31.298117] est[30.748377] total[111149056]max[30] M2[477998494.526686] count[2097152] std[15.097270] avg[21.326080] est[11.904392] total[113246208]max[30] M2[291761992.912811] count[2097152] std[11.795042] avg[17.685249] est[15.319354] total[115343360]max[30] M2[209023091.572831] count[2097152] std[9.983487] avg[16.296667] est[13.406508] ```
Thanks!
Merged #1236.