Skip to content

Instantly share code, notes, and snippets.

@nickva
Created February 27, 2025 23:22
Show Gist options
  • Save nickva/24d0223018b6b58bace70ad89e3bfa3e to your computer and use it in GitHub Desktop.
Save nickva/24d0223018b6b58bace70ad89e3bfa3e to your computer and use it in GitHub Desktop.
Quick and dirty concurrent config get benchmark for CouchDB
% 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).
@nickva
Copy link
Author

nickva commented Feb 27, 2025

> c(bench_config), bench_config:go(1000000, 100).
#{avg => 1.2176023,max => 1.825168,min => 0.214153,
  p75 => 1.690383,p90 => 1.798175,p99 => 1.824712,
  total => 1836970}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment