Skip to content

Commit

Permalink
Compaction: Allow snooze_period to be a float
Browse files Browse the repository at this point in the history
We are experiencing an issue similar to #1579, partly because we have
dozens of thousands of databases.

On our servers:
- `snooze_period = 0` leads to a significant CPU load,
- `snooze_period = 1` is too long for compaction to finish within 20
  hours (after 20 hours, compaction is stopped to allow other
  CPU-intensive processes to run, and when compaction restarts, it does
  not pick up where it left 4 hours earlier -- by the way proposal at
  #1775 would be really great to fix that!)

This commits allows to write `snooze_period = 0.3` in configuration.
  • Loading branch information
adrienverge committed Jan 28, 2019
1 parent edcb372 commit d593543
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rel/overlay/etc/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ min_file_size = 131072
; databases, the compaction_daemon can create significant CPU load when
; checking whether databases and view indexes need compacting. The
; snooze_period setting ensures a smoother CPU load. Defaults to
; 3 seconds wait.
; 3 seconds wait. Can be a float (e.g. write 0.3 for 300 ms).
; snooze_period = 3

[compactions]
Expand Down
8 changes: 4 additions & 4 deletions src/couch/src/couch_compaction_daemon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +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),
SnoozePeriod = config:get_float("compaction_daemon", "snooze_period", 3.0),
{ok, _} = couch_server:all_databases(
fun(DbName, Acc) ->
case ets:info(?CONFIG_ETS, size) =:= 0 of
Expand All @@ -140,7 +140,7 @@ compact_loop(Parent) ->
case check_period(Config) of
true ->
maybe_compact_db(Parent, DbName, Config),
ok = timer:sleep(SnoozePeriod * 1000);
ok = timer:sleep(trunc(SnoozePeriod * 1000));
false ->
ok
end
Expand Down Expand Up @@ -231,8 +231,8 @@ maybe_compact_views(DbName, [DDocName | Rest], Config) ->
timeout ->
ok
end,
SnoozePeriod = config:get_integer("compaction_daemon", "snooze_period", 3),
ok = timer:sleep(SnoozePeriod * 1000);
SnoozePeriod = config:get_float("compaction_daemon", "snooze_period", 3.0),
ok = timer:sleep(trunc(SnoozePeriod * 1000));
false ->
ok
end.
Expand Down

0 comments on commit d593543

Please sign in to comment.