Skip to content
Browse files

Optimised for fewest fun calls

  • Loading branch information...
1 parent 61435d1 commit f05c95e69798030c54b48c5692b78dd99472386f @russelldb committed Apr 3, 2012
Showing with 42 additions and 29 deletions.
  1. +42 −29 src/riak_kv_stat.erl
View
71 src/riak_kv_stat.erl
@@ -247,48 +247,61 @@ get_stats() ->
%% @spec update(term()) -> ok
%% @doc Update the given stat.
update(vnode_get) ->
- riak_core_metric_proc:update(?APP, vnode_gets, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_gets_total, 1);
+ riak_core_metric_proc:batch(?APP, vnode_gets, fun() ->
+ riak_core_metric_proc:update(?APP, vnode_gets, {1, slide:moment()}),
+ riak_core_metric_proc:update(?APP, vnode_gets_total, 1) end);
update(vnode_put) ->
- riak_core_metric_proc:update(?APP, vnode_puts, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_puts_total, 1);
+ riak_core_metric_proc:batch(?APP, vnode_puts, fun() ->
+ riak_core_metric_proc:update(?APP, vnode_puts, {1, slide:moment()}),
+ riak_core_metric_proc:update(?APP, vnode_puts_total, 1) end);
update(vnode_index_read) ->
- riak_core_metric_proc:update(?APP, vnode_index_reads, {1, slide:moment()}),
- riak_core_metric_counter:increment(?APP, vnode_index_reads_total);
+ riak_core_metric_proc:batch(?APP, vnode_index_reads, fun() ->
+ riak_core_metric_proc:update(?APP, vnode_index_reads, {1, slide:moment()}),
+ riak_core_metric_proc:update(?APP, vnode_index_reads_total, 1) end);
update({vnode_index_write, PostingsAdded, PostingsRemoved}) ->
- riak_core_metric_proc:update(?APP, vnode_index_writes, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_index_writes_total, 1),
- riak_core_metric_proc:update(?APP, vnode_index_writes_postings, {PostingsAdded, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_index_writes_postings_total, PostingsAdded),
- riak_core_metric_proc:update(?APP, vnode_index_deletes_postings, {PostingsRemoved, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_index_deletes_postings_total, PostingsRemoved);
+ riak_core_metric_proc:batch(?APP, vnode_index_writes, fun() ->
+ Moment = slide:moment(),
+ riak_core_metric_proc:update(?APP, vnode_index_writes, {1, Moment}),
+ riak_core_metric_proc:update(?APP, vnode_index_writes_total, 1),
+ riak_core_metric_proc:update(?APP, vnode_index_writes_postings, {PostingsAdded, Moment}),
+ riak_core_metric_proc:update(?APP, vnode_index_writes_postings_total, PostingsAdded),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes_postings, {PostingsRemoved, Moment}),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes_postings_total, PostingsRemoved) end);
update({vnode_index_delete, Postings}) ->
- riak_core_metric_proc:update(?APP, vnode_index_deletes, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_index_deletes_total, 1),
- riak_core_metric_proc:update(?APP, vnode_index_deletes_postings, {Postings, slide:moment()}),
- riak_core_metric_proc:update(?APP, vnode_index_deletes_postings_total, Postings);
+riak_core_metric_proc:batch(?APP, vnode_index_deletes, fun() ->
+ Moment = slide:moment(),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes, {1, Moment}),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes_total, 1),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes_postings, {Postings, Moment}),
+ riak_core_metric_proc:update(?APP, vnode_index_deletes_postings_total, Postings) end);
update({get_fsm, _Bucket, Microsecs, undefined, undefined}) ->
- riak_core_metric_proc:update(?APP, get_fsm_time, {Microsecs, slide:moment()}),
- riak_core_metric_proc:update(?APP, node_gets_total, 1);
+riak_core_metric_proc:batch(?APP, get_fsm_time, fun() ->
+ riak_core_metric_proc:update(?APP, get_fsm_time, {Microsecs, slide:moment()}),
+ riak_core_metric_proc:update(?APP, node_gets_total, 1) end);
update({get_fsm, _Bucket, Microsecs, NumSiblings, ObjSize}) ->
- riak_core_metric_proc:update(?APP, get_fsm_time, {Microsecs, slide:moment()}),
- riak_core_metric_proc:update(?APP, node_gets_total, 1),
- riak_core_metric_proc:update(?APP, node_get_fsm_siblings, {NumSiblings, slide:moment()}),
- riak_core_metric_proc:update(?APP, node_get_fsm_objsize, {ObjSize, slide:moment()});
+ riak_core_metric_proc:batch(?APP, get_fsm_time, fun() ->
+ Moment = slide:moment(),
+ riak_core_metric_proc:update(?APP, get_fsm_time, {Microsecs, Moment}),
+ riak_core_metric_proc:update(?APP, node_gets_total, 1),
+ riak_core_metric_proc:update(?APP, node_get_fsm_siblings, {NumSiblings, Moment}),
+ riak_core_metric_proc:update(?APP, node_get_fsm_objsize, {ObjSize, Moment}) end);
update({get_fsm_time, Microsecs}) ->
update({get_fsm, undefined, Microsecs, undefined, undefined});
update({put_fsm_time, Microsecs}) ->
- riak_core_metric_proc:update(?APP, put_fsm_time, {Microsecs, slide:moment()}),
- riak_core_metric_proc:update(?APP, node_puts_total, 1);
+ riak_core_metric_proc:batch(?APP, put_fsm_time, fun() ->
+ riak_core_metric_proc:update(?APP, put_fsm_time, {Microsecs, slide:moment()}),
+ riak_core_metric_proc:update(?APP, node_puts_total, 1) end);
update(pbc_connect) ->
- riak_core_metric_proc:update(?APP, pbc_connects, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, pbc_connects_total, 1),
- riak_core_metric_proc:update(?APP, pbc_active, 1);
+ riak_core_metric_proc:batch(?APP, vnode_gets, fun() ->
+ riak_core_metric_proc:update(?APP, pbc_connects, {1, slide:moment()}),
+ riak_core_metric_proc:update(?APP, pbc_connects_total, 1),
+ riak_core_metric_proc:update(?APP, pbc_active, 1) end);
update(pbc_disconnect) ->
riak_core_metric_proc:update(?APP, pbc_active, -1);
update(read_repairs) ->
- riak_core_metric_proc:update(?APP, read_repairs, {1, slide:moment()}),
- riak_core_metric_proc:update(?APP, read_repairs_total, 1);
+riak_core_metric_proc:batch(?APP, read_repairs, fun() ->
+ riak_core_metric_proc:update(?APP, read_repairs, {1, slide:moment()}),
+ riak_core_metric_proc:update(?APP, read_repairs_total, 1) end);
update(coord_redir) ->
riak_core_metric_proc:update(?APP, coord_redirs_total, 1);
update(mapper_start) ->

0 comments on commit f05c95e

Please sign in to comment.
Something went wrong with that request. Please try again.