Time unit problem with LatencyUtils 'recordLatency' method
Asked Answered
L

1

6

I am using the LatencyUtils package for tracking and reporting on the behavior of latencies across measurements:

For recording the time by this method, the time unit should be nanosecond, but in my case, the time recorded is in milliseconds. I want to know if there is a better way to record time in milliseconds?

The solution I use now is to multiply all the recorded time by one million. But I still hope that the results are in microseconds, so for the results I get, I divide it by one million.

public void addValue(Long val, long sampleCount) {
    sum += val * sampleCount;
    for (int i = 0; i < sampleCount; i++) {
        latencyStats.recordLatency(val*1000000);
    }
    histogram.add(latencyStats.getIntervalHistogram());
    max = Math.max(val, max);
    min = Math.min(val, min);
    updateValueCount(val,sampleCount);
}

@Override
public double getStandardDeviation() {
    return histogram.getStdDeviation()/1000000;
}

And the default constructor of LatencyUtil is like this:

private long lowestTrackableLatency = 1000L; /* 1 usec */
private long highestTrackableLatency = 3600000000000L; /* 1 hr */
private int numberOfSignificantValueDigits = 2;
private int intervalEstimatorWindowLength = 1024;
private long intervalEstimatorTimeCap = 10000000000L; /* 10 sec */
private PauseDetector pauseDetector = null;
public LatencyStats() {
    this(
            defaultBuilder.lowestTrackableLatency,
            defaultBuilder.highestTrackableLatency,
            defaultBuilder.numberOfSignificantValueDigits,
            defaultBuilder.intervalEstimatorWindowLength,
            defaultBuilder.intervalEstimatorTimeCap,
            defaultBuilder.pauseDetector
    );
}

So, in fact, the lowest trackable latency of LatencyUtil is also in nanoseconds. If I put a value in milliseconds, I am afraid that will affect the results of the record.

Lactary answered 11/7, 2019 at 9:54 Comment(5)
Wouldn't the actual unit not matter at all here? I think you can skip multiplying and dividing results, as long as you remember to present results in nanosecond units. Same would be if you recorded values in hours, no need for multiplying or dividing manually.Rosanarosane
@M.Prokhorov, what is disturbing is that recordLatency documentation mentions nanosec as the unitPerverse
@UBIKLOADPACK, as I understand it, they don't give a damn about actual UOM. They just accept integers and do some computations with them. Those can be years or picoseconds for all they care, the computation won't change. They mention nanos in context of best available time source precision, is my understanding.Rosanarosane
@M.Prokhorov, If you're sure about your answer, why not create an answer instead of comment, I'll be happy to give the bounty. ThanksPerverse
@UBIKLOADPACK, that'd be because I'm not sure about my answer, I learned about that library when I first read this question, and my whole knowledge of it comes from reading its javadoc and source code. Per usual when I'm commenting like this.Rosanarosane
M
0

I can offer you another Open Source Library that provides the Utility that can convert values from one time unit to another. Its called MgntUtils. See this javadoc for class TimeInterval. This is convenience class that holds time interval as numerical value and its associated TimeUnit. The class also provides methods of retrieval of its value as a long in needed scale (nanoseconds, milliseconds, seconds, minutes, hours or days) see methods toNanos(), toMillis(), toSeconds(), toMinutes(), toHours(), toDays(). You can find the library itself on Github and on Maven Central as maven artifacts. Here is an article about the library

Moonmoonbeam answered 16/7, 2019 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.