JMeter nanoThreadSleep property - how to use it?

I am setting up a load testing solution, and when I read the JMeter docs, I see that you can set many properties for test plans. I already have tests that work very well, and the results, graphs, etc., but when I tried to get a deeper understanding of JMeter and the accuracy of the results, etc., I came across the ad unit below.

From the JMeter documentation , I read the following:

# Whether to use System.nanoTime() - otherwise only use System.currentTimeMillis() sampleresult.useNanoTime=true # Use a background thread to calculate the nanoTime offset # Set this to <= 0 to disable the background thread sampleresult.nanoThreadSleep=5000 

Now I understand that nanotime will be based on a fixed but arbitrary start time, whereas currenttimeinmillis based on system time (i.e. on the wall). And I know that nanotime will be more accurate, so I'm interested in using it: I do load testing and require response time measurements to be as accurate and accurate as possible.

But the problem I am facing is understanding how to use nanoThreadSleep . What exactly is nanoscale displacement? Why do I want, or don't want, a background thread to calculate the offset of nanotimes? What happens if I turn on JMeter to start using the nanoteme, but donโ€™t use the nanoThreadSleep parameter explicitly?

I was looking for StackOverflow and Google for some explanation, but I can not find anything other than JMeter reporting it in the tiny commercial I put in here. Can others help me figure this out and how can I use it correctly and effectively?

+5
source share
1 answer

Looking at the JMeter code, I found the section below interesting. So the main thread is the one that sleeps for NANOTHREAD_SLEEP milliseconds, and then when it wakes up, it asks for the time.

This value should remain as high as possible so as not to add too much overhead to the sample, but should remain as low as possible to ensure sufficient accuracy.

If you are not using nanothread, then all the time it is calculated using System.nanoTime (), and this may or may not give additional accuracy. As a rule, high accuracy counters are strongly affected by frequency changes (for example, due to energy-saving modes). My opinion is that you donโ€™t have to worry about using System.nanoTime (), because you wonโ€™t be able to repeat the test to the nanosecond level . Even a millisecond seems very difficult for this.

Why use a background thread to calculate time? I think this is because if a thread only measures time, you can set it to the current time at any time during execution. If you are not using a background thread, I think that the time is updated only at the sampling point. With the thread on, I think time is updated more often (assuming NANOTHREAD_SLEEP well considered). I did not write JMeter, but I think that this is the philosophy behind the temporary thread.

Is this useful? It can probably compress extra precision. However, JMeter is used to test web application performance , where repeatability is poor due to network latency, resource usage, etc. . Even if you measure nanoseconds, people will be more interested in seconds and milliseconds and that the test is repeated.

CODE:

 private static class NanoOffset extends Thread { private static volatile long nanoOffset; static long getNanoOffset() { return nanoOffset; } @Override public void run() { // Wait longer than a clock pulse (generally 10-15ms) getOffset(30L); // Catch an early clock pulse to reduce slop. while(true) { getOffset(NANOTHREAD_SLEEP); // Can now afford to wait a bit longer between checks } } private void getOffset(long wait) { try { TimeUnit.MILLISECONDS.sleep(wait); long clock = System.currentTimeMillis(); long nano = SampleResult.sampleNsClockInMs(); nanoOffset = clock - nano; } catch (InterruptedException ignore) { // ignored } } } 
+1
source

Source: https://habr.com/ru/post/1214771/


All Articles