Oslo/blueprints/time monotonic
Authors
- Victor Stinner - victor.stinner@enovance.com
Rationale
Using time.time() to compute timeouts is wrong. The elapsed time may be wrong on update of the system clock. A monotonic clock should be used to avoid this issue.
For a longer rationale, read the 418.
Use time.monotonic()
Eventlet should use time_monotonic() instead of time.time(). Example of bug of time.time(): https://www.mail-archive.com/openstack-dev@lists.openstack.org/msg18697.html
For greenlet, the monotonic clock can be used with something like that:
eventlet.hubs._threadlocal.hub = eventlet.hubs.get_default_hub().Hub(monotonic_time)
time_monotonic() should be used for any function computing a timeout. Recent example: https://review.openstack.org/#/c/71003/
Implementation
The following patch is based on the file time_monotonic.py from my Trollius project. Trollius is tested on Linux, Mac OS X, Windows, FreeBSD and OpenIndiana (which is almost Solaris): https://review.openstack.org/#/c/85717/
Alternatives
- https://pypi.python.org/pypi/Monotime
- On Linux, it uses CLOCK_MONOTONIC_RAW which is wrong according to my PEP 418. Extract: "Slewing is generally desirable (i.e. we should use CLOCK_MONOTONIC, not CLOCK_MONOTONIC_RAW) if one wishes to measure "real" time (and not a time-like object like CPU cycles)."
- Monotime module doesn't support Windows nor Solaris. Does it matters for Oslo Incubator?
There is also python-monotonic-time, but it doesn't look to be available on PyPI: https://github.com/gavinbeatty/python-monotonic-time