time.time() under load between two machines
Jeff Epler
jepler at unpythonic.net
Fri Jul 22 11:03:27 EDT 2005
What makes you believe that the two machines' clocks are perfectly
synchronized? If they're not, it easily explains the result.
I wrote a simple client/server program similar to what you described.
Running on two RedHat 9 machines on a local network, I generally
observed a time delta of 2ms (compared to typical 0.17ms latency
reported by "ping"), never in a negative direction. These machines
times are synchronized by ntpd from the package ntp-4.1.2-0.rc1.2.
My program can be run like this:
rsh otherhost python timely.py -s | python timely.py -r
the values printed are the difference between the remote time before the
message is sent and the local time after the message is received.
You mention using Windows. I don't know whether Windows machines by
default use anything as sophisticated as ntpd to keep their clocks
accurate.
Whatever is going on in your case, I suspect it is the operating system,
not Python.
Jeff
import os, sys, time
def serve():
while 1:
data = struct.pack("!d", time.time())
os.write(1, data)
time.sleep(1)
def recv(fileno):
while 1:
data = struct.unpack("!d", os.read(fileno, 8))[0]
now = time.time()
print now - data
if sys.argv[1] == "-s":
serve()
else:
recv(0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050722/06ed2b24/attachment.sig>
More information about the Python-list
mailing list