couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [12/50] folsom commit: updated refs/heads/import-master to 4824aec
Date Thu, 31 Jul 2014 21:25:00 GMT
Fix histogram of type 'none'

* Before, after filling in the SIZE of the histogram, when adding new values the same element
was deleted and updated all the time.
* Tests are included.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/commit/19e5c24a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/tree/19e5c24a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/diff/19e5c24a

Branch: refs/heads/import-master
Commit: 19e5c24a77e62c136b91bf300c05352419fa8a39
Parents: e9be9f7
Author: Lastres <ramonlastres@gmail.com>
Authored: Tue Jun 18 14:31:53 2013 +0100
Committer: Lastres <ramonlastres@gmail.com>
Committed: Tue Jun 18 15:18:53 2013 +0100

----------------------------------------------------------------------
 include/folsom.hrl            |  2 +-
 src/folsom_sample_none.erl    |  8 +++-----
 test/folsom_erlang_checks.erl | 19 +++++++++++++++++--
 3 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/19e5c24a/include/folsom.hrl
----------------------------------------------------------------------
diff --git a/include/folsom.hrl b/include/folsom.hrl
index a999798..8be22d6 100644
--- a/include/folsom.hrl
+++ b/include/folsom.hrl
@@ -57,7 +57,7 @@
 
 -record(none, {
           size = ?DEFAULT_SIZE,
-          n = 0,
+          n = 1,
           reservoir = folsom_metrics_histogram_ets:new(folsom_none,[ordered_set, {write_concurrency,
true}, public])
          }).
 

http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/19e5c24a/src/folsom_sample_none.erl
----------------------------------------------------------------------
diff --git a/src/folsom_sample_none.erl b/src/folsom_sample_none.erl
index 08b3ca7..c0ebc32 100644
--- a/src/folsom_sample_none.erl
+++ b/src/folsom_sample_none.erl
@@ -37,14 +37,12 @@ new(Size) ->
     #none{size = Size}.
 
 update(#none{size = Size, reservoir = Reservoir, n = N} = Sample, Value)
-  when N < Size ->
+  when N =:= Size ->
     ets:insert(Reservoir, {N, Value}),
-    Sample#none{n = folsom_utils:get_ets_size(Reservoir) + 1};
+    Sample#none{n = 1};
 update(#none{reservoir = Reservoir, n = N} = Sample, Value) ->
-    Oldest = ets:first(Reservoir),
-    ets:delete(Reservoir, Oldest),
     ets:insert(Reservoir, {N, Value}),
-    Sample#none{n = folsom_utils:get_ets_size(Reservoir) + 1}.
+    Sample#none{n = N  + 1}.
 
 get_values(#none{reservoir = Reservoir}) ->
     {_, Values} = lists:unzip(ets:tab2list(Reservoir)),

http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/19e5c24a/test/folsom_erlang_checks.erl
----------------------------------------------------------------------
diff --git a/test/folsom_erlang_checks.erl b/test/folsom_erlang_checks.erl
index 6ea9a5a..710344d 100644
--- a/test/folsom_erlang_checks.erl
+++ b/test/folsom_erlang_checks.erl
@@ -44,6 +44,7 @@
 -define(HUGEDATA, lists:seq(1,10000)).
 
 -define(DATA1, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]).
+-define(DATA2, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]).
 
 -include("folsom.hrl").
 
@@ -59,6 +60,9 @@ create_metrics() ->
 
     ok = folsom_metrics:new_histogram(nonea, none, 5000),
 
+    ok = folsom_metrics:new_histogram(noneb, none, 10),
+    ok = folsom_metrics:new_histogram(nonec, none, 5),
+
     ok = folsom_metrics:new_histogram(timed, none, 5000),
     ok = folsom_metrics:new_histogram(timed2, none, 5000),
 
@@ -86,7 +90,7 @@ create_metrics() ->
     %% check a server got started for the spiral metric
     1 = length(supervisor:which_children(folsom_sample_slide_sup)),
 
-    15 = length(folsom_metrics:get_metrics()),
+    17 = length(folsom_metrics:get_metrics()),
 
     ?debugFmt("~n~nmetrics: ~p~n", [folsom_metrics:get_metrics()]).
 
@@ -128,6 +132,10 @@ populate_metrics() ->
 
     [ok = folsom_metrics:notify({nonea, Value}) || Value <- ?DATA1],
 
+    [ok = folsom_metrics:notify({noneb, Value}) || Value <- ?DATA2],
+
+    [ok = folsom_metrics:notify({nonec, Value}) || Value <- ?DATA2],
+
     3.141592653589793 = folsom_metrics:histogram_timed_update(timed, math, pi, []),
 
     Begin = folsom_metrics:histogram_timed_begin(timed2),
@@ -180,6 +188,10 @@ check_metrics() ->
 
     2 = folsom_metrics:get_metric_value(<<"gauge">>),
 
+    [11,12,13,14,15,6,7,8,9,10] = folsom_metrics:get_metric_value(noneb),
+
+    [11,12,13,14,15] = folsom_metrics:get_metric_value(nonec),
+
     Histogram1 = folsom_metrics:get_histogram_statistics(<<"uniform">>),
     histogram_checks(Histogram1),
 
@@ -284,7 +296,7 @@ check_group_metrics() ->
     {counter, 0} = lists:keyfind(counter,1,Metrics).
 
 delete_metrics() ->
-    17 = length(ets:tab2list(?FOLSOM_TABLE)),
+    19 = length(ets:tab2list(?FOLSOM_TABLE)),
 
     ok = folsom_metrics:delete_metric(counter),
     ok = folsom_metrics:delete_metric(counter2),
@@ -299,6 +311,9 @@ delete_metrics() ->
     ok = folsom_metrics:delete_metric(historya),
 
     ok = folsom_metrics:delete_metric(nonea),
+    ok = folsom_metrics:delete_metric(noneb),
+    ok = folsom_metrics:delete_metric(nonec),
+
     ok = folsom_metrics:delete_metric(timed),
     ok = folsom_metrics:delete_metric(timed2),
     ok = folsom_metrics:delete_metric(testcounter),


Mime
View raw message