Bug 44600 - 1-ms resolution timer when running under Java 1.5+
1-ms resolution timer when running under Java 1.5+
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: Main
2.3.1
PC Windows XP
: P2 enhancement (vote)
: ---
Assigned To: JMeter issues mailing list
http://mail-archives.apache.org/mod_m...
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-03-13 14:30 UTC by Matt McClure
Modified: 2008-03-29 07:51 UTC (History)
0 users



Attachments
Uses System.nanoTime() to achieve 1-ms resolution (5.91 KB, patch)
2008-03-13 14:30 UTC, Matt McClure
Details | Diff
Updated patch (5.17 KB, patch)
2008-03-15 10:22 UTC, Matt McClure
Details | Diff
Patch using reflection (5.74 KB, patch)
2008-03-23 06:12 UTC, Matt McClure
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.