You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by bheuvel <gi...@git.apache.org> on 2016/01/08 14:13:55 UTC

[GitHub] cloudstack pull request: Factor in inaccurancy of System.nanoTime ...

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 <bv...@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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: Factor in inaccurancy of System.nanoTime ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: Factor in inaccurancy of System.nanoTime ...

Posted by cristofolini <gi...@git.apache.org>.
Github user cristofolini commented on the pull request:

    https://github.com/apache/cloudstack/pull/1324#issuecomment-170381531
  
    I've had tests involving sleep calls fail on me seemingly arbitrarily, to the point where simply re-running them would give me a passing result. I think something as simple as an I/O or CPU scheduler could impact the measurement enough to make the test fail (I've seen different rates of failure while fiddling around with the schedulers on my linux setup, but then again that's anecdotal evidence at best). It also seems to me that the margin applied here is the proper size to allow for a slightly more brand measure without being large to the point of compromising test accuracy to a great degree. Code LGTM too.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: Factor in inaccurancy of System.nanoTime ...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on the pull request:

    https://github.com/apache/cloudstack/pull/1324#issuecomment-170385290
  
    validating by compile:
    ```
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 12:00 min
    [INFO] Finished at: 2016-01-10T20:48:34+01:00
    [INFO] Final Memory: 114M/813M
    [INFO] ------------------------------------------------------------------------
    ``` LGTM
    pinging RM @remibergsma 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cloudstack pull request: Factor in inaccurancy of System.nanoTime ...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on the pull request:

    https://github.com/apache/cloudstack/pull/1324#issuecomment-170354023
  
    makes sense. I doubt, this will do but it will reduce the chance of failure. It will not produce false negatives beyond the specified precision margin of the functionality. LGTM.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---