Created
February 27, 2025 23:22
-
-
Save nickva/24d0223018b6b58bace70ad89e3bfa3e to your computer and use it in GitHub Desktop.
Quick and dirty concurrent config get benchmark for CouchDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Save in ./couchdb top level | |
% | |
% $ ./dev/run ... | |
% $ remsh | |
% | |
% > bench_config:go(1000000, 100). | |
% #{max => 5.620738,min => 0.62035,total => 5633922, | |
% avg => 3.82163797,p50 => 4.568493,p75 => 5.314903, | |
% p90 => 5.519178} | |
% | |
-module(bench_config). | |
-export([go/2]). | |
go(N, Procs) -> | |
T0 = erlang:monotonic_time(), | |
PidRefs = [start_getter(N) || _ <- lists:seq(1, Procs)], | |
Results0 = lists:sort(gather(PidRefs, [])), | |
Results = [Result/N || Result <- Results0], | |
#{ | |
total => erlang:convert_time_unit(erlang:monotonic_time() - T0, native, microsecond), | |
min => lists:min(Results), | |
max => lists:max(Results), | |
avg => lists:sum(Results) / Procs, | |
p75 => lists:nth(round(Procs * 0.75), Results), | |
p90 => lists:nth(round(Procs * 0.9), Results), | |
p99 => lists:nth(round(Procs * 0.99), Results) | |
}. | |
gather([], Acc) -> | |
Acc; | |
gather([{_Pid, Ref} | Rest], Acc) -> | |
gather(Rest, [receive {'DOWN', Ref, _, _, R} -> R end | Acc]). | |
start_getter(N) -> | |
spawn_monitor(fun() -> getter(N, erlang:monotonic_time()) end). | |
getter(0, T0) -> | |
Dt = erlang:convert_time_unit(erlang:monotonic_time() - T0, native, microsecond), | |
exit(Dt); | |
getter(N, T0) -> | |
_ = config:get("chttpd", "port"), | |
getter(N - 1, T0). |
Author
nickva
commented
Feb 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment