nickva commented on PR #5:
URL: https://github.com/apache/couchdb-folsom/pull/5#issuecomment-1590342163

   However trying a persistent term + counter with `[write_concurrency]` option 
did yield a 10x improvement:
   
   ```erlang
   -module(upstats_counter).
   
   -export([go/0, go/1, go/2]).
   
   go() ->
       go(1000, 10000).
   
   go(N) ->
       go(N, 10000).
   
   go(N, X) ->
       Ref = counters:new(1024, [write_concurrency]),
       persistent_term:put(term, Ref),
       T0 = erlang:monotonic_time(),
       Workers = [spawn_monitor(fun() ->
           rand:seed(default, os:timestamp()),
           upstat(X)
       end) || _ <- lists:seq(1, N)],
       {_Pids, Refs} = lists:unzip(Workers),
       WorkersSet = sets:from_list(Refs, [{version,2}]),
       ok = wait_workers(WorkersSet),
       Dt = erlang:monotonic_time() - T0,
       erlang:convert_time_unit(Dt, native, millisecond).
   
   upstat(0) ->
       ok;
   upstat(Times) ->
       Ref = persistent_term:get(term),
       counters:add(Ref, rand:uniform(1024), 100),
       upstat(Times - 1).
   
   wait_workers(Workers) when is_map(Workers) ->
       case sets:size(Workers) of
           0 ->
               ok;
           _ ->
               receive
                   {'DOWN', Ref, process, _, normal} ->
                       Workers1 = sets:del_element(Ref, Workers),
                       wait_workers(Workers1);
                   {'DOWN', Ref, process, _, Err} ->
                       Workers1 = sets:del_element(Ref, Workers),
                       io:format("~n worker ~p crashed: ~p~n", [Ref, Err]),
                       wait_workers(Workers1)
               end
       end.
   ```
   
   ```erlang
   ([email protected])18> upstats_counter:go(50000, 1000).
   1385
   ([email protected])19> upstats_counter:go(50000, 1000).
   1425
   ([email protected])20> upstats_counter:go(50000, 1000).
   1427
   ([email protected])21> upstats_counter:go(50000, 1000).
   1438
   ([email protected])22> upstats:go(50000, 1000).
   15131
   ([email protected])23> upstats:go(50000, 1000).
   16075
   ([email protected])24> upstats:go(50000, 1000).
   14869
   ```
   
   So that might be an interesting to use to replace folsom histograms with.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to