Skip to content

Commit 6200135

Browse files
t3hnarbrian-brazil
authored andcommitted
slightly decrease thread contention by synchronizing once rather than "number quantiles + 1" times (#481)
Signed-off-by: Yaroslav Klymko <[email protected]>
1 parent 4e0e752 commit 6200135

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

simpleclient/src/main/java/io/prometheus/client/CKMSQuantiles.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public CKMSQuantiles(Quantile[] quantiles) {
8787
*
8888
* @param value
8989
*/
90-
public synchronized void insert(double value) {
90+
public void insert(double value) {
9191
buffer[bufferCount] = value;
9292
bufferCount++;
9393

@@ -104,7 +104,7 @@ public synchronized void insert(double value) {
104104
* Queried quantile, e.g. 0.50 or 0.99.
105105
* @return Estimated value at that quantile.
106106
*/
107-
public synchronized double get(double q) {
107+
public double get(double q) {
108108
// clear the buffer
109109
insertBatch();
110110
compress();

simpleclient/src/main/java/io/prometheus/client/TimeWindowQuantiles.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public TimeWindowQuantiles(Quantile[] quantiles, long maxAgeSeconds, int ageBuck
2727
this.durationBetweenRotatesMillis = TimeUnit.SECONDS.toMillis(maxAgeSeconds) / ageBuckets;
2828
}
2929

30-
public double get(double q) {
30+
public synchronized double get(double q) {
3131
CKMSQuantiles currentBucket = rotate();
3232
return currentBucket.get(q);
3333
}
3434

35-
public void insert(double value) {
35+
public synchronized void insert(double value) {
3636
rotate();
3737
for (CKMSQuantiles ckmsQuantiles : ringBuffer) {
3838
ckmsQuantiles.insert(value);
3939
}
4040
}
4141

42-
private synchronized CKMSQuantiles rotate() {
42+
private CKMSQuantiles rotate() {
4343
long timeSinceLastRotateMillis = System.currentTimeMillis() - lastRotateTimestampMillis;
4444
while (timeSinceLastRotateMillis > durationBetweenRotatesMillis) {
4545
ringBuffer[currentBucket] = new CKMSQuantiles(quantiles);

0 commit comments

Comments
 (0)