This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5ef942afdc79f1b012f2a2d48f722ea50afca899
Author: Jan Lehnardt <j...@apache.org>
AuthorDate: Mon Mar 5 16:06:21 2018 +0100

    feat: introduce snooze_period to reduce compaction_daemon load.
    
    This commit introduces a snooze period for the compaction daemon
    to apply inbetween moving on from one database compaction to
    another, and from one view group to another.
    
    The result is that on db-per-user setups, the compaction daemon
    doesn’t cause a CPU spike every check_interval seconds.
---
 src/couch/src/couch_compaction_daemon.erl          | 8 ++++++--
 src/couch/test/couchdb_compaction_daemon_tests.erl | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/couch/src/couch_compaction_daemon.erl 
b/src/couch/src/couch_compaction_daemon.erl
index 9371119..59555f1 100644
--- a/src/couch/src/couch_compaction_daemon.erl
+++ b/src/couch/src/couch_compaction_daemon.erl
@@ -126,6 +126,7 @@ handle_config_terminate(_Server, _Reason, _State) ->
     erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), 
restart_config_listener).
 
 compact_loop(Parent) ->
+    SnoozePeriod = config:get_integer("compaction_daemon", "snooze_period", 3),
     {ok, _} = couch_server:all_databases(
         fun(DbName, Acc) ->
             case ets:info(?CONFIG_ETS, size) =:= 0 of
@@ -138,7 +139,8 @@ compact_loop(Parent) ->
                 {ok, Config} ->
                     case check_period(Config) of
                     true ->
-                        maybe_compact_db(Parent, DbName, Config);
+                        maybe_compact_db(Parent, DbName, Config),
+                        ok = timer:sleep(SnoozePeriod * 1000);
                     false ->
                         ok
                     end
@@ -229,7 +231,9 @@ maybe_compact_views(DbName, [DDocName | Rest], Config) ->
             maybe_compact_views(DbName, Rest, Config);
         timeout ->
             ok
-        end;
+        end,
+        SnoozePeriod = config:get_integer("compaction_daemon", 
"snooze_period", 3),
+        ok = timer:sleep(SnoozePeriod * 1000);
     false ->
         ok
     end.
diff --git a/src/couch/test/couchdb_compaction_daemon_tests.erl 
b/src/couch/test/couchdb_compaction_daemon_tests.erl
index 47f35a0..c10ddee 100644
--- a/src/couch/test/couchdb_compaction_daemon_tests.erl
+++ b/src/couch/test/couchdb_compaction_daemon_tests.erl
@@ -24,6 +24,7 @@
 start() ->
     Ctx = test_util:start_couch(),
     ok = config:set("compaction_daemon", "check_interval", "3", false),
+    ok = config:set("compaction_daemon", "snooze_period", "0", false),
     ok = config:set("compaction_daemon", "min_file_size", "100000", false),
     ok = config:delete("compactions", "_default", false),
     ok = meck:new(?MODS_TO_MOCK, [passthrough]),

-- 
To stop receiving notification emails like this one, please contact
j...@apache.org.

Reply via email to