Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optimise samplerate = 1 case #3

Merged
merged 1 commit into from

2 participants

@RJ
RJ commented

Optimisation to avoid doing random stuff when sample rate is 1.

No data to support this, but it seemed sensible.

@lpgauth
Owner

Looks good, I'll test it this PM and merge if there's no regressions.

@lpgauth lpgauth merged commit c894291 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2012
  1. @RJ
This page is out of date. Refresh to see the latest.
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.
Something went wrong with that request. Please try again.