Compaction: Allow snooze_period to be a float#1880
Conversation
|
I don't know why tests fail, it compiles OK on my computer 🤔 |
|
The logs say that the What happens when you run Did you perhaps break startup because the |
538b375 to
d593543
Compare
|
Hi @wohali, thanks for your guidance on that. Unfortunately But compiling and running it myself helped me finding the causes:
I've modified this commit to fix that, and tested compiled CouchDB with different values (floats and integers): it works (I've also checked that these values are correctly read, using |
|
@adrienverge Try: |
|
Can I suggest not to change the existing config attribute, but instead add a new one - "snooze_period_ms" representing time in milliseconds (as integer) and then abstract snooze period's getter with something like this? get_snooze_period() ->
Default = config:get_integer("compaction_daemon", "snooze_period", 3),
case config:get_integer("compaction_daemon", "snooze_period_ms", -1) of
-1 -> Default * 1000;
SnoozePeriod -> SnoozePeriod
end.This will allow not to wrestle with the floats, be consistent with the rest of the config where time attributes defined as integers and will not break every CouchDB deployment that happened to have that attribute customized, in case people miss the requirement to change their config during an upgrade to be a float. As for PR itself the test |
|
@eiri thanks for your feedback. I sure can try do add a new In my opinion, accepting both integers and floats for |
|
fwiw this code right now is not supporting both integers and floats, but ignores %% Can read customized integer
(node1@127.0.0.1)3> config:get_integer("compaction_daemon", "snooze_period", 5).
1
%% but ignoring it when trying to read it as a float
(node1@127.0.0.1)2> config:get_float("compaction_daemon", "snooze_period", 5.0).
5.0Hence my note that it'd be good to have tests for this change. |
|
@eiri thanks for your feedback; my goal was to support both integers and floats. I'm trying to do my best to implement a simple change and try to make CouchDB better, but please take into account that I don't know anything about Erlang. I spent a few hours and I'm still struggling. That's why constructive help (like your code snippets) is welcome! Do you prefer the |
|
@adrienverge I agree that the best approach would be moving to This would be consistent with a lot of our other config params which are specified in ms, rather than as a float. There's some precedent for "switch to a new configuration way, support old config approach if still exists" - see what Jan did here: #1602 and specifically https://github.com/apache/couchdb/pull/1602/files#diff-083efc44719b2a6e73526a2de5969175R394 or https://github.com/apache/couchdb/pull/1602/files#diff-b8549b33b7019d19458ba8ee619f1373R60 |
d20cd65 to
9bc171d
Compare
|
@wohali thanks a lot for your explanations: a "smooth migration" from → I introduced a About tests, I tried to write some, but:
Should I keep trying to write a test? If yes, is there a preferred approach? |
@adrienverge: It's more of "implicit vs explicit config" type of thing, neither approach necessary better or worse and you have a fair point about two attributes controlling the same parameter been confusing. Historically times in Couch's config kept as ints and @wohali idea about deprecating old attribute should take care of the config's ambiguity, so I appreciate you going along with my suggestion. Now about the tests. Erlang way of dealing with testing of not exported functions is to add unit tests in the same module within However the unit testing in Erlang is notorious for its complexity and writing tests around config is even more tricky, because get_snooze_period_test_() ->
{
foreach,
fun() ->
meck:new(config, [passthrough])
end,
fun(_) ->
meck:unload()
end,
[
{"should return default value without config attributes",
fun should_default_without_config/0},
{"should respect old config attribute",
fun should_respect_old_config/0},
{"should respect old config set to zero",
fun should_respect_old_config_zero/0},
{"should respect new config attribute",
fun should_respect_new_config/0},
{"should respect new config set to zero",
fun should_respect_new_config_zero/0}
]
}.
should_default_without_config() ->
?assertEqual(3000, get_snooze_period()).
should_respect_old_config() ->
meck:expect(config, get_integer, fun
("compaction_daemon", "snooze_period", _) -> 1;
(_, _, Default) -> Default
end),
?assertEqual(1000, get_snooze_period()).
should_respect_old_config_zero() ->
meck:expect(config, get_integer, fun
("compaction_daemon", "snooze_period", _) -> 0;
(_, _, Default) -> Default
end),
?assertEqual(0, get_snooze_period()).
should_respect_new_config() ->
meck:expect(config, get_integer, fun
("compaction_daemon", "snooze_period", _) -> 1;
("compaction_daemon", "snooze_period_ms", _) -> 300;
(_, _, Default) -> Default
end),
?assertEqual(300, get_snooze_period()).
should_respect_new_config_zero() ->
meck:expect(config, get_integer, fun
("compaction_daemon", "snooze_period", _) -> 1;
("compaction_daemon", "snooze_period_ms", _) -> 0;
(_, _, Default) -> Default
end),
?assertEqual(0, get_snooze_period()).As for |
9bc171d to
c3eb760
Compare
|
Amazing (this way of writing tests is similar to Rust actually). I took your tests as is, because they do exactly what needs to be done (no config / only Pull request updated (and rebased on latest master). |
We are experiencing an issue similar to apache#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 apache#1775 would be really great to fix that!) This commit introduces a new option `snooze_period_ms` (measured in milliseconds), and deprecates `snooze_period` while still supporting it for obvious legacy reasons.
c3eb760 to
0447a04
Compare
|
lgtm. @adrienverge can you please rebase? @wohali are you all right with merging this? |
|
Nicely done! Great first contribution @adrienverge! |
wohali
left a comment
There was a problem hiding this comment.
Very nicely done @adrienverge !
|
Thanks for your help on this! For info, I tried to update docs accordingly: apache/couchdb-documentation#386 |
This commit introduces a new option `snooze_period_ms` (measured in milliseconds), and deprecates `snooze_period` while still supporting it for obvious legacy reasons.
This commit introduces a new option `snooze_period_ms` (measured in milliseconds), and deprecates `snooze_period` while still supporting it for obvious legacy reasons.
We are experiencing an issue similar to #1579, partly because we have
dozens of thousands of databases.
On our servers:
snooze_period = 0leads to a significant CPU load,snooze_period = 1is too long for compaction to finish within 20hours (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
Enhance autocompaction daemon to pick up where we left off last time #1775 would be really great to fix that!)
This commits allows to write
snooze_period = 0.3in configuration.