[JAVA-550] Use System.nanoTime instead of System.currentTimeMillis for taking latency measurements in ReplicaSetStatus.Updater thread Created: 03/Apr/12  Updated: 18/Jun/12  Resolved: 05/Apr/12

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.7
Fix Version/s: 2.8.0

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

According to Java API documentation, System.nanoTime is preferred for taking elapsed time measurements (http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#nanoTime()).



 Comments   
Comment by Jeffrey Yemin [ 18/Jun/12 ]

Closing for 2.8.0 release.

Comment by auto [ 05/Apr/12 ]

Author:

{u'login': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-550: switch to System.nanoTime to measure elapsed time
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/3204ae547b93a043eebcca761fc2665210f3678d

Comment by auto [ 04/Apr/12 ]

Author:

{u'login': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-550: switch to System.nanoTime to measure elapsed time
Branch: release-2.7.x
https://github.com/mongodb/mongo-java-driver/commit/fa538effc4e7e4e2fd3a200d9f6b6f38fd0fc2eb

Comment by Jeffrey Yemin [ 03/Apr/12 ]

Test program:

public class MillisVsNanosTest {
    public static void main(String[] args) throws UnknownHostException {
        Mongo m = new Mongo("127.0.0.1:47017");
        DB db = m.getDB("admin");
        db.command("isMaster");
 
        for (int i = 0; i < 100; i++) {
            long milliStart = System.currentTimeMillis();
            db.command("isMaster");
            long milliEnd = System.currentTimeMillis();
            long elapsedTime = milliEnd - milliStart;
            System.out.print(elapsedTime + " ");
        }
        
        System.out.println();
        System.out.println();
 
        for (int i = 0; i < 100; i++) {
            long nanoStart = System.nanoTime();
            db.command("isMaster");
            long nanoEnd = System.nanoTime();
            long elapsedTime = nanoEnd - nanoStart;
            System.out.print(((long) elapsedTime) / 1000000 + " ");
        }
 
        System.out.println();
        System.out.println();
    }
}

nanoTime doesn't give any more consistent results than currentTimeMillis with JDK 6 on OS X.

Generated at Thu Feb 08 08:52:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.