Просмотр исходного кода

Do not schedule member culling if pool has fixed size

If init_count matches max_count, attempting to cull members will never
modify pool state. So avoid starting the timer and doing work for
nothing.
Seth Falcon 12 лет назад
Родитель
Сommit
4fe27018b0
2 измененных файлов с 21 добавлено и 0 удалено
  1. 5 0
      src/pooler.erl
  2. 16 0
      test/pooler_tests.erl

+ 5 - 0
src/pooler.erl

@@ -574,6 +574,11 @@ add_member_to_consumer(MemberPid, CPid, CPMap) ->
 cull_members_from_pool(#pool{cull_interval = {0, _}} = Pool) ->
     %% 0 cull_interval means do not cull
     Pool;
+cull_members_from_pool(#pool{init_count = C, max_count = C} = Pool) ->
+    %% if init_count matches max_count, then we will not dynamically
+    %% add capacity and should not schedule culling regardless of
+    %% cull_interval config.
+    Pool;
 cull_members_from_pool(#pool{name = PoolName,
                              free_count = FreeCount,
                              init_count = InitCount,

+ 16 - 0
test/pooler_tests.erl

@@ -516,6 +516,22 @@ pooler_scheduled_cull_test_() ->
                timer:sleep(250),
                ?assertEqual(10, length(pooler:pool_stats(test_pool_1))),
                [ pooler:return_member(test_pool_1, P) || P <- Pids ]
+       end},
+
+      {"no cull when init_count matches max_count",
+       %% not sure how to verify this. But this test at least
+       %% exercises the code path.
+       fun() ->
+               Config = [{name, test_static_pool_1},
+                         {max_count, 2},
+                         {init_count, 2},
+                         {start_mfa, {pooled_gs, start_link, [{"static-0"}]}},
+                         {cull_interval, {200, ms}}], % ignored
+               pooler:new_pool(Config),
+               P = pooler:take_member(test_static_pool_1),
+               ?assertMatch({"static-0", _}, pooled_gs:get_id(P)),
+               pooler:return_member(test_static_pool_1, P),
+               ok
        end}
      ]}.