Permalink
Browse files

Merge pull request #3 from irccloud/master

Optimise samplerate = 1 case
  • Loading branch information...
2 parents 6f78233 + faf1f95 commit c8942914e80e1cec775c305eb5f7092f7029e38e @lpgauth committed Nov 12, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/statsderl.erl
View
17 src/statsderl.erl
@@ -89,16 +89,23 @@ code_change(_OldVsn, State, _Extra) ->
%% Internal Function Definitions
%% ------------------------------------------------------------------
+send(Method, Key, Value, 1) ->
+ send_packet(Method, Key, Value, 1);
+
+send(Method, Key, Value, 1.0) ->
+ send_packet(Method, Key, Value, 1.0);
+
send(Method, Key, Value, SampleRate) ->
maybe_seed(),
case random:uniform() =< SampleRate of
- true ->
- Packet = generate_packet(Method, Key, Value, SampleRate),
- gen_server:cast(?MODULE, {send, Packet});
- false ->
- ok
+ true -> send_packet(Method, Key, Value, SampleRate);
+ false -> ok
end.
+send_packet(Method, Key, Value, SampleRate) ->
+ Packet = generate_packet(Method, Key, Value, SampleRate),
+ gen_server:cast(?MODULE, {send, Packet}).
+
now_diff_ms(Timestamp) ->
timer:now_diff(os:timestamp(), Timestamp) div 1000.

0 comments on commit c894291

Please sign in to comment.