Created
October 23, 2009 17:17
-
-
Save kocolosk/217055 to your computer and use it in GitHub Desktop.
measures couch_config lookup throughput
This file contains 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
-module (config_bench). | |
-export ([doit/2]). | |
doit(Conns, Reps) -> | |
doit(Conns, Reps, false). | |
doit(Conns, Reps, AlsoWrite) -> | |
Conf = couch_config:all(), | |
Begin = erlang:now(), | |
Self = self(), | |
Writer = if AlsoWrite -> spawn(fun write_stuff/0); true -> Self end, | |
[spawn(fun() -> grab(Self, Conf, Reps) end) || _I <- lists:seq(1,Conns)], | |
ok = wait_result(Conns), | |
Writer ! stop, | |
% seconds to run the test | |
timer:now_diff(erlang:now(), Begin)/1000000. | |
wait_result(0) -> | |
ok; | |
wait_result(N) -> | |
receive done -> wait_result(N-1) end. | |
write_stuff() -> | |
receive stop -> ok | |
after 0 -> | |
couch_config:set("some_block", "foo", | |
binary_to_list(couch_uuids:new())), | |
write_stuff() | |
end. | |
% lookup all config values | |
grab(Parent, _Conf, 0) -> | |
Parent ! done; | |
grab(Parent, Conf, M) -> | |
{Keys, _Values} = lists:unzip(Conf), | |
[couch_config:get(K,V) || {K,V} <- Keys], | |
grab(Parent, Conf, M-1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment