-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][broker] Fix rate limiter token bucket and clock consistency iss…
…ues causing excessive throttling and connection timeouts (#23930)
- Loading branch information
Showing
23 changed files
with
1,090 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ch/src/main/java/org/apache/pulsar/broker/qos/DefaultMonotonicSnapshotClockBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.pulsar.broker.qos; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Fork(3) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Thread) | ||
public class DefaultMonotonicSnapshotClockBenchmark { | ||
private DefaultMonotonicSnapshotClock monotonicSnapshotClock = | ||
new DefaultMonotonicSnapshotClock(TimeUnit.MILLISECONDS.toNanos(1), System::nanoTime); | ||
|
||
@TearDown(Level.Iteration) | ||
public void teardown() { | ||
monotonicSnapshotClock.close(); | ||
} | ||
|
||
@Threads(1) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanos001Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, false); | ||
} | ||
|
||
@Threads(10) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanos010Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, false); | ||
} | ||
|
||
@Threads(100) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanos100Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, false); | ||
} | ||
|
||
@Threads(1) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanosRequestSnapshot001Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, true); | ||
} | ||
|
||
@Threads(10) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanosRequestSnapshot010Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, true); | ||
} | ||
|
||
@Threads(100) | ||
@Benchmark | ||
@Measurement(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
@Warmup(time = 10, timeUnit = TimeUnit.SECONDS, iterations = 1) | ||
public void getTickNanosRequestSnapshot100Threads(Blackhole blackhole) { | ||
consumeTokenAndGetTokens(blackhole, true); | ||
} | ||
|
||
private void consumeTokenAndGetTokens(Blackhole blackhole, boolean requestSnapshot) { | ||
// blackhole is used to ensure that the compiler doesn't do dead code elimination | ||
blackhole.consume(monotonicSnapshotClock.getTickNanos(requestSnapshot)); | ||
} | ||
} |
Oops, something went wrong.