Zero Burst Under Load
This singleton ships to a 32-core service. readConfig reads a properties file and never returns 0 for either key.
public final class RateLimiter {
private static RateLimiter instance; // note: not volatile
private int burst;
private long refillNanos;
private RateLimiter() {
this.burst = readConfig("burst"); // 200
this.refillNanos = readConfig("refill") * 1_000_000L;
}
public static RateLimiter get() {
if (instance == null) { // fast path, no lock
synchronized (RateLimiter.class) {
if (instance == null) {
instance = new RateLimiter();
}
}
}
return instance;
}
public int burst() { return burst; }
}
Roughly once a week, under a traffic spike, a request thread sees burst() return 0 and every caller is throttled. What is happening?
Sign in to answer questions and track your progress
Sign In