Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add hubs.default_clock and use time.monotonic #303
The asyncio project also uses time.monotonic() by default.
For example information of monotonic clock, see the PEP 418:
Note: I wrote and implemented the PEP 418 in Python 3.3.
* Add a new eventlet.hubs.default_clock variable to be able to choose the default clock for hubs. * Modify hub classes to use default_clock as the default clock * default_clock uses time.monotonic if available (Python 3.3 or newer), or time.time The asyncio project also uses time.monotonic() by default. For example information of monotonic clock, see the PEP 418: https://www.python.org/dev/peps/pep-0418/ Note: I wrote and implemented the PEP 418 in Python 3.3.
Do you have info about monotonic for 2.7? I only found these:
Monotonic clock is of course the only way to go. Huge thanks for bringing this up, and patch.
OpenStack uses https://pypi.python.org/pypi/monotonic
I backported the PEP 418 to Python 2, but I didn't publish it on PyPI, since most users only care of time.monotonic() and there are already projects providing a monotonic clock for Python 2.
Sorry, I don't understand. The idea of default_clock is to not add a new dependency to eventlet, and let users choose the clock.
Right now, there is no way to choose the clock for all threads. See for example https://review.openstack.org/#/c/286838/ which looks a little bit to a hack to me, that's why I proposed to add default_clock option.
My default_clock option is a compromise for a practical issue, the need of an external dependency.
Well. Another option is to integrate a monotonic clock to eventlet directly. But I have no preference, they are various implementations which advantages and drawbacks. So I prefer to continue to use a 3rd party module for that.
There is a way to choose clock for all threads with a small risk.
There's no way you could set
Another way to restate my previous attack on
Better option to let users choose clock, without risk, with hard guarantee that incorrect clock wasn't used is environment variable.
And your version with
Thanks for monotonic libraries list. I will insert one into Eventlet source, the practice is already established with
Please don't use CLOCK_MONOTONIC_RAW. You really want CLOCK_MONOTONIC which is adjusted to use seconds. For time.monotonic(), it was important that the unit is second, since users expect this unit. It's a good thing to adjust CLOCK_MONOTONIC with NTP to really measure seconds and not an arbitrary unit (slower or faster than seconds).
CLOCK_MONOTONIC_RAW must be reserved for low-level applications synchronizing time between multiple computers.
When I wrote this issue, I was thinking at asyncio where the event loop is created explicitly. It looks like the creation of the eventlet is more implicit, and it's harder to control when it is created. So I'm not sure that my design (default_clock) works to configure a clock.
The problem is to set the clock function before the first event loop is created.
Linux clock_gettime() manual page:
NTP is used to fix (adjust) clocks to get seconds instead of a clock slower or faster than atomic clocks using seconds.
NTP adjustement is a good thing ;-)
Or: "[CLOCK_MONOTONIC] ... the timestamps from the hardware clock source are being scaled, per adjustments made via adjtime/NTP, to correct for imprecision in the hardware clock rate that would otherwise make it drift relative to real time." http://stackoverflow.com/questions/25583498/clock-monotonic-vs-clock-monotonic-raw-truncated-values
hub.BaseHub on init , patcher import original by EVENTLET_CLOCK (MODULE) and get method EVENTLET_CLOCK_METHOD (default name to MODULE) EVENTLET_CLOCK_METHOD, is a method returning float in seconds, defaults to monotonic All considering the eventlet#303 OK usages. EVENTLET_CLOCK=time python proc.py anyway default, EVENTLET_CLOCK=monotic python proc.py EVENTLET_CLOCK=my.pkg EVENTLET_CLOCK_METHOD=clock python proc.py (it will use my.pkg.clock for getting clock in seconds)