Revert changes to async_nif and re-enable stats. Fixed selective recv.
This commit is contained in:
parent
2393257bef
commit
c9a4ab8325
3 changed files with 62 additions and 61 deletions
|
@ -393,10 +393,8 @@ async_nif_worker_fn(void *arg)
|
||||||
/* Queue is empty so we wait for more work to arrive. */
|
/* Queue is empty so we wait for more work to arrive. */
|
||||||
if (q->num_workers > ASYNC_NIF_MIN_WORKERS) {
|
if (q->num_workers > ASYNC_NIF_MIN_WORKERS) {
|
||||||
enif_mutex_unlock(q->reqs_mutex);
|
enif_mutex_unlock(q->reqs_mutex);
|
||||||
if (tries == 0 && q == we->q) {
|
if (tries == 0 && q == we->q) break; // we've tried all queues, thread exit
|
||||||
tries = async_nif->num_queues;
|
else {
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
tries--;
|
tries--;
|
||||||
__sync_fetch_and_add(&q->num_workers, -1);
|
__sync_fetch_and_add(&q->num_workers, -1);
|
||||||
q = q->next;
|
q = q->next;
|
||||||
|
|
|
@ -21,22 +21,28 @@
|
||||||
%%
|
%%
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
||||||
-define(ASYNC_NIF_CALL(Fun, Args),
|
-spec async_nif_enqueue(function(), [term()]) -> term() | {error, term()}.
|
||||||
begin
|
async_nif_enqueue(F, A) ->
|
||||||
NIFRef = erlang:make_ref(),
|
R = erlang:make_ref(),
|
||||||
case erlang:apply(Fun, [NIFRef|Args]) of
|
case erlang:apply(F, [R|A]) of
|
||||||
{ok, enqueued} ->
|
{ok, enqueued} ->
|
||||||
receive
|
receive
|
||||||
{NIFRef, {error, shutdown}=Error} ->
|
{R, {error, shutdown}=Error} ->
|
||||||
%% Work unit was queued, but not executed.
|
%% Work unit was queued, but not executed.
|
||||||
Error;
|
Error;
|
||||||
{NIFRef, {error, _Reason}=Error} ->
|
{R, {error, _Reason}=Error} ->
|
||||||
%% Work unit returned an error.
|
%% Work unit returned an error.
|
||||||
Error;
|
Error;
|
||||||
{NIFRef, Reply} ->
|
{R, Reply} ->
|
||||||
Reply
|
Reply
|
||||||
end;
|
end;
|
||||||
|
{error, eagain} ->
|
||||||
|
%% Work unit was not queued, try again.
|
||||||
|
async_nif_enqueue(F, A);
|
||||||
|
%{error, enomem} ->
|
||||||
|
%{error, shutdown} ->
|
||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end
|
end.
|
||||||
end).
|
|
||||||
|
-define(ASYNC_NIF_CALL(Fun, Args), async_nif_enqueue(Fun, Args)).
|
||||||
|
|
|
@ -340,26 +340,23 @@ is_empty(#state{connection=Connection, table=Table}) ->
|
||||||
|
|
||||||
%% @doc Get the status information for this wterl backend
|
%% @doc Get the status information for this wterl backend
|
||||||
-spec status(state()) -> [{atom(), term()}].
|
-spec status(state()) -> [{atom(), term()}].
|
||||||
status(_) ->
|
status(#state{connection=Connection, table=Table}) ->
|
||||||
[].
|
case wterl:cursor_open(Connection, Table) of
|
||||||
|
{ok, Cursor} ->
|
||||||
%% status(#state{connection=Connection, table=Table}) ->
|
TheStats =
|
||||||
%% case wterl:cursor_open(Connection, Table) of
|
case fetch_status(Cursor) of
|
||||||
%% {ok, Cursor} ->
|
{ok, Stats} ->
|
||||||
%% TheStats =
|
Stats;
|
||||||
%% case fetch_status(Cursor) of
|
{error, {eperm, _}} -> % TODO: review/fix this logic
|
||||||
%% {ok, Stats} ->
|
{ok, []};
|
||||||
%% Stats;
|
_ ->
|
||||||
%% {error, {eperm, _}} -> % TODO: review/fix this logic
|
{ok, []}
|
||||||
%% {ok, []};
|
end,
|
||||||
%% _ ->
|
wterl:cursor_close(Cursor),
|
||||||
%% {ok, []}
|
TheStats;
|
||||||
%% end,
|
{error, Reason2} ->
|
||||||
%% wterl:cursor_close(Cursor),
|
{error, Reason2}
|
||||||
%% TheStats;
|
end.
|
||||||
%% {error, Reason2} ->
|
|
||||||
%% {error, Reason2}
|
|
||||||
%% end.
|
|
||||||
|
|
||||||
%% @doc Register an asynchronous callback
|
%% @doc Register an asynchronous callback
|
||||||
-spec callback(reference(), any(), state()) -> {ok, state()}.
|
-spec callback(reference(), any(), state()) -> {ok, state()}.
|
||||||
|
@ -546,15 +543,15 @@ from_index_key(LKey) ->
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% Return all status from wterl statistics cursor
|
%% Return all status from wterl statistics cursor
|
||||||
%% fetch_status(Cursor) ->
|
fetch_status(Cursor) ->
|
||||||
%% {ok, fetch_status(Cursor, wterl:cursor_next_value(Cursor), [])}.
|
{ok, fetch_status(Cursor, wterl:cursor_next_value(Cursor), [])}.
|
||||||
%% fetch_status(_Cursor, {error, _}, Acc) ->
|
fetch_status(_Cursor, {error, _}, Acc) ->
|
||||||
%% lists:reverse(Acc);
|
lists:reverse(Acc);
|
||||||
%% fetch_status(_Cursor, not_found, Acc) ->
|
fetch_status(_Cursor, not_found, Acc) ->
|
||||||
%% lists:reverse(Acc);
|
lists:reverse(Acc);
|
||||||
%% fetch_status(Cursor, {ok, Stat}, Acc) ->
|
fetch_status(Cursor, {ok, Stat}, Acc) ->
|
||||||
%% [What,Val|_] = [binary_to_list(B) || B <- binary:split(Stat, [<<0>>], [global])],
|
[What,Val|_] = [binary_to_list(B) || B <- binary:split(Stat, [<<0>>], [global])],
|
||||||
%% fetch_status(Cursor, wterl:cursor_next_value(Cursor), [{What,Val}|Acc]).
|
fetch_status(Cursor, wterl:cursor_next_value(Cursor), [{What,Val}|Acc]).
|
||||||
|
|
||||||
size_cache(RequestedSize) ->
|
size_cache(RequestedSize) ->
|
||||||
Size =
|
Size =
|
||||||
|
|
Loading…
Reference in a new issue