GitHub user bheuvel opened a pull request:

    https://github.com/apache/cloudstack/pull/1324

    Factor in inaccurancy of System.nanoTime in class Profiler

    The time diff measurement by the class Profiler, is done by 
System.nanoTime().
    System.nanoTime() is not 100% accurate (lots of info on this on the web). 
The inaccurance seems to vary/depend with different dependencies 
(multi-core/OS/kernels).
    
    Problem:
    In my case the code which measures `Thread.sleep(ONE_SECOND);` ~~takes~~ 
measures 999 milliseconds, which breaks the test expecting the sleep of 1000 
milliseconds to ~~take~~ measure at least 1000 milliseconds.
    
    Solution:
    A `MARGIN` (of 100 milliseconds) is already present to factor in some time 
for overhead/surrounding code which adds time. Another margin could be added to 
factor in the possible time measurement error.
    To limit additional lines of code, the constant `ONE_SECOND`, which is used 
by the testcase (sleep), is increased from 1000 milliseconds to `1000l + 
(MARGIN / 10)` (effectively 1010 milliseconds).
    
    Thereby the inaccurancy on my system of ~1% ("faster") is caught as the 
`sleep(1010)` is measured as '1009' milliseconds.
    
    
    
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/bheuvel/cloudstack testprofiler-second

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cloudstack/pull/1324.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1324
    
----
commit dbb10a4ed5dc763b4c603e5cc3f2b70a202c0a2b
Author: Bob <bvandenheu...@schubergphilis.com>
Date:   2016-01-08T12:31:27Z

    Factor in inaccurancy of System.nanoTime

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to