You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/10/22 19:59:13 UTC

[couchdb] branch replicator-job-churn-fix created (now 036ade3)

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

vatamane pushed a change to branch replicator-job-churn-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 036ade3  Avoid churning replication jobs if there is enough room to run pending jobs

This branch includes the following new commits:

     new 036ade3  Avoid churning replication jobs if there is enough room to run pending jobs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Avoid churning replication jobs if there is enough room to run pending jobs

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch replicator-job-churn-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 036ade3836c3970e9fabf37078d52e9a5dff83a9
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Tue Oct 22 14:27:13 2019 -0400

    Avoid churning replication jobs if there is enough room to run pending jobs
    
    When rescheduling jobs, make sure to stops existing job as much as needed to
    make room for the pending jobs.
---
 .../src/couch_replicator_scheduler.erl             | 39 ++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/couch_replicator/src/couch_replicator_scheduler.erl b/src/couch_replicator/src/couch_replicator_scheduler.erl
index 7fe417a..73f94ff 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler.erl
@@ -760,8 +760,12 @@ rotate_jobs(State, ChurnSoFar) ->
     % Reduce MaxChurn by the number of already stopped jobs in the
     % current rescheduling cycle.
     Churn = max(0, MaxChurn - ChurnSoFar),
-    if Running =< MaxJobs ->
-        StopCount = lists:min([Pending, Running, Churn]),
+    SlotsAvailable = MaxJobs - Running,
+    if SlotsAvailable >= 0 ->
+        % If there is are enough SlotsAvailable reduce StopCount to avoid
+        % unnesessarily stopping jobs. `stop_jobs/3` ignores 0 or negaive
+        % values so we don't worry about that here.
+        StopCount = lists:min([Pending - SlotsAvailable, Running, Churn]),
         stop_jobs(StopCount, true, State),
         StartCount = max(0, MaxJobs - running_job_count()),
         start_jobs(StartCount, State);
@@ -1047,6 +1051,8 @@ scheduler_test_() ->
             t_stop_oldest_first(),
             t_start_oldest_first(),
             t_jobs_churn_even_if_not_all_max_jobs_are_running(),
+            t_jobs_dont_churn_if_there_are_available_running_slots(),
+            t_start_only_pending_jobs_do_not_churn_existing_ones(),
             t_dont_stop_if_nothing_pending(),
             t_max_churn_limits_number_of_rotated_jobs(),
             t_existing_jobs(),
@@ -1207,11 +1213,40 @@ t_jobs_churn_even_if_not_all_max_jobs_are_running() ->
             continuous(5)
         ]),
         reschedule(mock_state(2, 2)),
+        % 7 would stop running and 2 and 5 will start since they will be the
+        % oldest pending jobs
         ?assertEqual({2, 1}, run_stop_count()),
         ?assertEqual([7], jobs_stopped())
     end).
 
 
+t_jobs_dont_churn_if_there_are_available_running_slots() ->
+     ?_test(begin
+        setup_jobs([
+            continuous_running(1),
+            continuous_running(2)
+        ]),
+        reschedule(mock_state(2, 2)),
+        ?assertEqual({2, 0}, run_stop_count()),
+        ?assertEqual([], jobs_stopped()),
+        ?assertEqual(0, meck:num_calls(couch_replicator_scheduler_sup, start_child, 1))
+    end).
+
+
+t_start_only_pending_jobs_do_not_churn_existing_ones() ->
+     ?_test(begin
+        setup_jobs([
+            continuous(1),
+            continuous_running(2)
+        ]),
+        reschedule(mock_state(2, 2)),
+        ?assertEqual(1, meck:num_calls(couch_replicator_scheduler_sup, start_child, 1)),
+        ?assertEqual([], jobs_stopped()),
+        ?assertEqual({2, 0}, run_stop_count()),
+        ?assertEqual(1, meck:num_calls(couch_replicator_scheduler_sup, start_child, 1))
+    end).
+
+
 t_dont_stop_if_nothing_pending() ->
     ?_test(begin
         setup_jobs([continuous_running(1), continuous_running(2)]),