-
Notifications
You must be signed in to change notification settings - Fork 4k
Introduce jitter metric based on RFC 1889 Appendix A #8586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,195
−73
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aae2554
init
GGraziadei 2aad8a2
allocate suppliers once
GGraziadei 5cb1936
improve jitter definition
GGraziadei 5aa8264
add documentation
GGraziadei 946715d
format
GGraziadei ac4e3b1
format
GGraziadei 23247e3
fix checkstyle
GGraziadei ce8e2b1
fix RFC 1889 jitter definition, guarantee jitter decay if stable latency
GGraziadei f040770
minor changes
GGraziadei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
storm-client/src/jvm/org/apache/storm/metrics2/EwmaGauge.java
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
|
rzo1 marked this conversation as resolved.
Outdated
|
||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.storm.metrics2; | ||
|
|
||
| import static org.apache.storm.utils.ConfigUtils.RFC1889_ALPHA; | ||
|
|
||
| import com.codahale.metrics.Gauge; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** | ||
| * Lock-free jitter estimator following RFC 1889 Section 6.3.1. | ||
|
rzo1 marked this conversation as resolved.
Outdated
|
||
| * The jitter accumulator is stored as raw IEEE 754 bits in an AtomicLong | ||
| * so that CAS can be used without locks. | ||
| * Thread safety: addValue is lock-free; getValue is wait-free. | ||
| */ | ||
| public class EwmaGauge implements Gauge<Double> { | ||
|
|
||
| private static final long UNSEEDED = Long.MIN_VALUE; | ||
| private static final long ZERO_BITS = Double.doubleToLongBits(0.0); | ||
|
|
||
| private final AtomicLong lastTransit = new AtomicLong(UNSEEDED); | ||
| private final AtomicLong jitterBits = new AtomicLong(ZERO_BITS); | ||
| private final double alpha; | ||
|
|
||
| EwmaGauge(double alpha) { | ||
| if (alpha <= 0.0 || alpha >= 1.0 || Double.isNaN(alpha)) { | ||
| throw new IllegalArgumentException( | ||
| "alpha must be in (0, 1), got: " + alpha); | ||
| } | ||
| this.alpha = alpha; | ||
| } | ||
|
|
||
| EwmaGauge() { | ||
| this(RFC1889_ALPHA); // 1.0 / 16.0 | ||
| } | ||
|
|
||
| /** | ||
| * Update the jitter estimate. | ||
| * | ||
| * @param transitMs transit time for this tuple: {@code arrival - timestamp} | ||
| * Negative values are silently ignored. | ||
| */ | ||
| public void addValue(long transitMs) { | ||
| if (transitMs < 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Seed on the very first packet: store transit, nothing to diff against yet. | ||
| if (lastTransit.compareAndSet(UNSEEDED, transitMs)) { | ||
| return; | ||
| } | ||
|
|
||
| long prev = lastTransit.getAndSet(transitMs); | ||
| if (prev == UNSEEDED) { | ||
| // Lost a race during seeding; prev is not a real transit value. | ||
| return; | ||
| } | ||
|
rzo1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| double d = Math.abs(transitMs - prev); | ||
|
rzo1 marked this conversation as resolved.
|
||
|
|
||
| long currentBits; | ||
| long updatedBits; | ||
| do { | ||
| currentBits = jitterBits.get(); | ||
| double currentJitter = Double.longBitsToDouble(currentBits); | ||
| double updatedJitter = currentJitter + alpha * (d - currentJitter); | ||
| updatedBits = Double.doubleToLongBits(updatedJitter); | ||
| } while (!jitterBits.compareAndSet(currentBits, updatedBits)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the current jitter estimate in timestamp units. | ||
| */ | ||
| @Override | ||
| public Double getValue() { | ||
| return Double.longBitsToDouble(jitterBits.get()); | ||
| } | ||
| } | ||
|
rzo1 marked this conversation as resolved.
Outdated
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.