'import paramiko' takes 1.5s on Windows (_measureTickSize)

John Arbash Meinel john at arbash-meinel.com
Sat Jul 12 18:57:29 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I was working on a simple test, and noticing that it was taking a really
long time to run. So I ran the profiler to see what was going on.

It seems that as part of Test.setUp() we go around and clear up all of
our hooks, which include smart server hooks. Which causes us to import
the ssh.py module, which causes us to import paramiko.

Nothing particularly terrible there, though we could probably make some
of that more lazy.

What does concern me is this result:

~ 1 0 1.5569 1.2677   Crypto.Util.randpool:242(_measureTickSize)

That is reproducible with:
$ time python -c 'import paramiko'
real    0m1.701s

It seems to be done as part of RandomPool.__init__()

The specific function does:
# Compute 100 differences
t=time.time()
h.update(`t`)
i = 0
j = 0
while i < 100:
~    t2=time.time()
~    h.update(`(i,j,t2)`)
~    j += 1
~    delta=int((t2-t)*1e6)
~    if delta:
~        interval[i] = delta
~        i += 1
~        t=t2


However, time.time() on windows only has a resolution of ~15ms. So
getting 100 new ticks takes... 15ms * 100 = 1.5s (no surprise there).

It turns out that on *windows* you should be using time.clock() which
uses a high resolution timer. (On Linux, time.clock() measures CPU time,
which isn't good for this particular use.)

Does anyone know who to contact in the Crypto group to get this fixed?
Should we in the short-term be trying to monkey patch the random
generator stuff so that we don't spend 1.5s doing *nothing* every time
we even *think* about opening up an ssh connection? (Note, this is
happening at *import* time, so we may never even connect over ssh.)

I'm trying to send this to a few people who might at least know who to
contact next. I think what I've generally done is something like:

_time_func = time.time
if sys.platform == 'win32':
~  _time_func = time.clock

I'd really like to see something like this done here, as it is rather
abusive to waste 1.5s spinning every time we import 'ssh.py'.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh48IgACgkQJdeBCYSNAANpZgCfY7OYmUWPvHAi2l0hI7NPQ0iD
XMgAnishQp3zU24MLXTls42AkxYqyPcO
=64qF
-----END PGP SIGNATURE-----



More information about the bazaar mailing list