Bug 44600

Summary: 1-ms resolution timer when running under Java 1.5+
Product: JMeter - Now in Github Reporter: Matt McClure <matthewlmcclure+asf>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: 2.3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://mail-archives.apache.org/mod_mbox/jakarta-jmeter-user/200803.mbox/%3ce48c5e540803111906w752decact32b33df64f10d5f8@mail.gmail.com%3e
Attachments: Uses System.nanoTime() to achieve 1-ms resolution
Updated patch
Patch using reflection

Description Matt McClure 2008-03-13 14:30:51 UTC
Created attachment 21665 [details]
Uses System.nanoTime() to achieve 1-ms resolution

The timer, as implemented using System.currentTimeMillis() in JMeter 2.3.1's SampleResult class, provides approximately 10-ms resolution on Windows.

I'd like to see 1-ms resolution.
Comment 1 Sebb 2008-03-13 14:50:11 UTC
Thanks for the patch.

However, there are some problems with it:

2 public createTestSample() methods are deleted by the patch.

Access to the static fields reference...Clock needs to be synchronized - or the fields need to be final.

Also, the code requires Java 1.5; JMeter is currently targeted at 1.4, but this may change.
Comment 2 Matt McClure 2008-03-13 14:57:09 UTC
(In reply to comment #1)
> 2 public createTestSample() methods are deleted by the patch.

I removed them because I didn't find any callers, but I'll put them back since you prefer it.

> Access to the static fields reference...Clock needs to be synchronized - or the
> fields need to be final.

Which would you prefer?

> Also, the code requires Java 1.5; JMeter is currently targeted at 1.4, but this
> may change.

Would you prefer a patch that's conditional on the JVM version?
Comment 3 Sebb 2008-03-13 15:22:22 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > 2 public createTestSample() methods are deleted by the patch.
> 
> I removed them because I didn't find any callers, but I'll put them back since
> you prefer it.

Methods cannot be arbitrarily removed.

> > Access to the static fields reference...Clock needs to be synchronized - or the
> > fields need to be final.
> 
> Which would you prefer?
> 

Final is safer and likely cheaper.

> > Also, the code requires Java 1.5; JMeter is currently targeted at 1.4, but this
> > may change.
> 
> Would you prefer a patch that's conditional on the JVM version?
> 

Depends how convoluted it becomes.
Comment 4 Matt McClure 2008-03-15 10:22:41 UTC
Created attachment 21672 [details]
Updated patch

I think this new patch addresses your concerns.
Comment 5 Sebb 2008-03-16 14:28:57 UTC
Thanks, the new patch should allow the code to run on Java 1.4 or 1.5.

However, it requires Java 1.5 to build.
It would be better if the code also compiled on 1.4.
Comment 6 Matt McClure 2008-03-22 07:01:27 UTC
(In reply to comment #5)
> It would be better if the code also compiled on 1.4.

I took another step in that direction, but it got ugly quickly.  I'm open to suggestions if you have a clean-ish way to do a conditional compile.

My first attempt used Ant to copy a 1.4- or 1.5-compatible implementation to the source directory before the javac task.
Comment 7 Sebb 2008-03-22 07:23:46 UTC
Yes, it's not easy to do.

The code needs to compile on 1.4 and run on 1.4+.

I think the only way to do it is to use reflection to see if the method exists, and use it if so; if not, then revert to the default.
Comment 8 Matt McClure 2008-03-23 06:12:49 UTC
Created attachment 21702 [details]
Patch using reflection

(In reply to comment #7)
> The code needs to compile on 1.4 and run on 1.4+.
> 
> I think the only way to do it is to use reflection to see if the method exists,
> and use it if so; if not, then revert to the default.

Try this new patch using reflection.
Comment 9 Sebb 2008-03-28 18:11:47 UTC
Thanks a lot.

The reflection patch looks fine; committed to SVN in r642469.
Comment 10 Matt McClure 2008-03-29 07:51:15 UTC
(In reply to comment #9)
> Thanks a lot.

You're welcome.  Thanks for accepting it.
Comment 11 The ASF infrastructure team 2022-09-24 20:37:41 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2083