-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23738 from vespa-engine/balder/implement-decay-ov…
…er-time - Refactor to allow for different decay method.
- Loading branch information
Showing
6 changed files
with
207 additions
and
62 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
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
43 changes: 43 additions & 0 deletions
43
container-search/src/main/java/com/yahoo/search/dispatch/RequestDuration.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,43 @@ | ||
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | ||
package com.yahoo.search.dispatch; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
/** | ||
* Contains start and and time. Exposes a duration, and lets you measure the time difference between 2 requests. | ||
* It does use System.nanoTime to get a steady clock. | ||
* | ||
* @author baldersheim | ||
*/ | ||
class RequestDuration { | ||
private final long startTime; | ||
private long endTime; | ||
RequestDuration() { | ||
this(System.nanoTime()); | ||
} | ||
private RequestDuration(long startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
RequestDuration complete() { | ||
endTime = System.nanoTime(); | ||
return this; | ||
} | ||
private RequestDuration complete(long duration) { | ||
endTime = startTime + duration; | ||
return this; | ||
} | ||
Duration duration() { | ||
return Duration.ofNanos(endTime - startTime); | ||
} | ||
Duration difference(RequestDuration prev) { | ||
return Duration.ofNanos(Math.abs(endTime - prev.endTime)); | ||
} | ||
static RequestDuration of(Duration duration) { | ||
return new RequestDuration().complete(duration.toNanos()); | ||
} | ||
static RequestDuration of(Instant sinceEpoch, Duration duration) { | ||
return new RequestDuration(sinceEpoch.toEpochMilli()*1_000_000).complete(duration.toNanos()); | ||
} | ||
} |
Oops, something went wrong.