Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Log down the redis url with the number of dropped
Browse files Browse the repository at this point in the history
count.
  • Loading branch information
omarkj committed Nov 27, 2013
1 parent df34a5c commit 6db9b41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/logplex_queue.erl
Expand Up @@ -85,6 +85,8 @@ out(NameOrPid, Num) when (is_atom(NameOrPid) orelse is_pid(NameOrPid)) andalso i
Packet
end.

-spec info(atom()|pid()) ->
{pos_integer(), pos_integer()}.
info(NameOrPid) when is_atom(NameOrPid); is_pid(NameOrPid) ->
gen_server:call(NameOrPid, info, ?TIMEOUT).

Expand Down Expand Up @@ -174,8 +176,15 @@ handle_call(_Msg, _From, State) ->
%% @hidden
%%--------------------------------------------------------------------
handle_cast({in, _Packet}, #state{dict=Dict, dropped_stat_key=StatKey, length=Length, max_length=MaxLength, num_dropped=NumDropped}=State) when Length >= MaxLength ->
logplex_stats:incr(StatKey),
logplex_realtime:incr(StatKey),
RedisUrl = case dict:find(redis_url, Dict) of

This comment has been minimized.

Copy link
@ferd

ferd Nov 28, 2013

Contributor

How big is the dict, and how often are we calling this? If this is overflow control and requires many lookups on a large dict, this can be a bit risky.

This comment has been minimized.

Copy link
@omarkj

omarkj Nov 28, 2013

Author Contributor

The dict is not big: https://github.com/heroku/logplex/blob/master/src/logplex_shard.erl#L263

Might be worth moving it into the state instead.

This comment has been minimized.

Copy link
@ferd

ferd Nov 28, 2013

Contributor

Agreed. Also I wouldn't be surprised that at this size, a lists:keyfind or orddict would be faster than a dict. Though updating this will be as annoying as updating the state record instead.

{ok, Value} ->
Value;
undefined ->
undefined
end,
logplex_stats:incr(#queue_stat{key=StatKey,
redis_url=RedisUrl}),
case dict:find(producer_callback, Dict) of
{ok, Fun} -> Fun(self(), stop_accepting);
error -> ok
Expand Down
8 changes: 6 additions & 2 deletions src/logplex_stats.erl
Expand Up @@ -42,8 +42,8 @@ incr(Key) ->
incr(Key, 1).

-spec incr(#drain_stat{} | #channel_stat{} | #logplex_stat{} |
list() | atom(),
integer()) -> any().
#queue_stat{} | list() | atom(), integer()) ->
any().
incr(Key, Incr) when is_integer(Incr) ->
try ets:update_counter(?MODULE, Key, Incr)
catch error:badarg ->
Expand Down Expand Up @@ -163,6 +163,10 @@ log_stat(UnixTS, #logplex_stat{module=Mod, key=K}, Val) ->
io:format("m=logplex_stats ts=~p system module=~p ~200p=~p~n",
[UnixTS, Mod, K, Val]);

log_stat(UnixTS, #queue_stat{redis_url=RedisUrl, key=Key}, Val) ->
io:format("m=logplex_stats ts=~p redis_url=~p ~p=~p~n",

This comment has been minimized.

Copy link
@ferd

ferd Nov 28, 2013

Contributor

You should io:format(user, Str, Args) here, in order to skip the middleman.

This comment has been minimized.

Copy link
@archaelus

archaelus Nov 28, 2013

Contributor

Actually this is supposed to go directly to stdout. Is there a way to bypass 'user' and friends? io:format(standard_io, ...) or something?

This comment has been minimized.

Copy link
@ferd

ferd Nov 28, 2013

Contributor

We use user pretty much everywhere. There is standard_error but the ownership of stdio is reserved by user itself. If you try to steal it, it generates a warning on boot.

[UnixTS, RedisUrl, Key, Val]);

log_stat(UnixTS, {Class, Key}, Val) ->
io:format("m=logplex_stats ts=~p freeform class=~p key=~p count=~p~n",
[UnixTS, Class, Key, Val]);
Expand Down

0 comments on commit 6db9b41

Please sign in to comment.