Guest User

Untitled

a guest
Apr 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. -module (config_bench).
  2. -export ([doit/2]).
  3.  
  4. doit(Conns, Reps) ->
  5. doit(Conns, Reps, false).
  6.  
  7. doit(Conns, Reps, AlsoWrite) ->
  8. Conf = couch_config:all(),
  9. Begin = erlang:now(),
  10. Self = self(),
  11. Writer = if AlsoWrite -> spawn(fun write_stuff/0); true -> Self end,
  12. [spawn(fun() -> grab(Self, Conf, Reps) end) || _I <- lists:seq(1,Conns)],
  13. ok = wait_result(Conns),
  14. Writer ! stop,
  15. % seconds to run the test
  16. timer:now_diff(erlang:now(), Begin)/1000000.
  17.  
  18. wait_result(0) ->
  19. ok;
  20. wait_result(N) ->
  21. receive done -> wait_result(N-1) end.
  22.  
  23. write_stuff() ->
  24. receive stop -> ok
  25. after 0 ->
  26. couch_config:set("some_block", "foo",
  27. binary_to_list(couch_uuids:new())),
  28. write_stuff()
  29. end.
  30.  
  31. % lookup all config values
  32. grab(Parent, _Conf, 0) ->
  33. Parent ! done;
  34. grab(Parent, Conf, M) ->
  35. {Keys, _Values} = lists:unzip(Conf),
  36. [couch_config:get(K,V) || {K,V} <- Keys],
  37. grab(Parent, Conf, M-1).
Add Comment
Please, Sign In to add comment