From 48419ce4d02ee5d7fe1cd32878e17d187bff34ae Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Wed, 21 Aug 2013 14:19:52 -0400 Subject: [PATCH] Start the penalty after queues are 25% full because a) that makes sense, and b) that avoids some odd badarith errors when PctBusy is very small. --- src/async_nif.hrl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/async_nif.hrl b/src/async_nif.hrl index e410def..bb10115 100644 --- a/src/async_nif.hrl +++ b/src/async_nif.hrl @@ -22,13 +22,15 @@ %% ------------------------------------------------------------------- -define(ASYNC_NIF_CALL(Fun, Args), - F = fun(F, A) -> + F = fun(F) -> R = erlang:make_ref(), - case erlang:apply(F, [R|A]) of + case erlang:apply(Fun, [R|Args]) of {ok, {enqueued, PctBusy}} -> - case PctBusy of - 0.0 -> ok; - _ -> erlang:bump_reductions(erlang:trunc(2000 * PctBusy)) + if + PctBusy > 0.25 andalso PctBusy =< 1.0 -> + erlang:bump_reductions(erlang:trunc(2000 * PctBusy)); + true -> + ok end, receive {R, {error, shutdown}=Error} -> @@ -41,9 +43,9 @@ Reply end; {error, eagain} -> - F(F, A); + F(F); Other -> Other end end, - F(Fun, Args)). + F(F)).