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

Add ability to update rate limiter #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

black-adder
Copy link
Contributor

Signed-off-by: Won Jun Jang [email protected]

Which problem is this PR solving?

  • The current way the rate limiting sampler is updated involves the sampler being reconstructed; this has the unfortunate side effect of the balance being reinitialized to full which will generate a new sample. If you are updating thousands of instances with a new rate limiting rate, this will generate thousands of new traces. This PR adds the ability to update the rate limiter so that the proportional balance is retained on update.

cf. jaegertracing/jaeger-client-go#320

@codecov
Copy link

codecov bot commented Jul 2, 2018

Codecov Report

Merging #17 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #17      +/-   ##
============================================
+ Coverage     84.77%   84.96%   +0.19%     
- Complexity      608      618      +10     
============================================
  Files            94       94              
  Lines          2410     2428      +18     
  Branches        271      271              
============================================
+ Hits           2043     2063      +20     
+ Misses          276      275       -1     
+ Partials         91       90       -1
Impacted Files Coverage Δ Complexity Δ
...r/jaeger/samplers/GuaranteedThroughputSampler.java 88.88% <100%> (ø) 7 <0> (ø) ⬇️
.../com/uber/jaeger/samplers/RateLimitingSampler.java 82.6% <100%> (+15.94%) 10 <5> (+4) ⬆️
...c/main/java/com/uber/jaeger/utils/RateLimiter.java 100% <100%> (ø) 8 <6> (+3) ⬆️
.../uber/jaeger/samplers/RemoteControlledSampler.java 86.53% <100%> (+0.67%) 23 <3> (+3) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a82dd0...0a5f30a. Read the comment docs.

return SamplingStatus.of(this.rateLimiter.checkCredit(1.0), tags);
}

@Override
public boolean equals(Object other) {
public synchronized boolean equals(Object other) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be synchronized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function and the update function are called at the same time, there could(?) be a race condition on the variable maxTracesPerSecond. Might be overkill

}

private double getMaxBalance(double maxTracesPerSecond) {
return maxTracesPerSecond < 1.0 ? 1.0 : maxTracesPerSecond;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 1.0? Could you refactor the magic number into a constant?
I'm not a fan of hardcoding this number here because we'll have to update the client when we need to change this number.

private final Clock clock;
private double balance;
private double maxBalance;
private long lastTick;

public RateLimiter(double creditsPerSecond, double maxBalance) {
this(creditsPerSecond, maxBalance, new SystemClock());
this(creditsPerSecond, maxBalance, new SystemClock(), maxBalance * new Random().nextDouble());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we cache the Random()?

Signed-off-by: Won Jun Jang <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants