tools.wdcat@tools-bastion-03:~$ time python -c "import flask" real 0m0.401s user 0m0.136s sys 0m0.060s tools.wdcat@tools-bastion-03:~$ time www/python/venv/bin/python -c "import flask" real 0m15.167s user 0m0.231s sys 0m1.847s
From a quick look using strace, most of the time seems to be spent in stat() and open() calls a la
13:02:09.982560 stat("/data/project/wdcat/www/python/venv/lib/python2.7/encodings", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0 <0.004214>
13:02:09.986888 stat("/data/project/wdcat/www/python/venv/lib/python2.7/encodings", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0 <0.006956>
13:02:09.994088 stat("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecs", 0x7ffc2d0434f0) = -1 ENOENT (No such file or directory) <0.002802>
13:02:09.997010 open("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecs.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003352>
13:02:10.000458 open("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecs.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003547>
13:02:10.004121 open("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecsmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003752>
13:02:10.008077 open("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecs.py", O_RDONLY) = -1 ENOENT (No such file or directory) <0.002851>
13:02:10.011045 open("/data/project/wdcat/www/python/venv/lib/python2.7/encodings/codecs.pyc", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003704>
13:02:10.014930 stat("/data/project/wdcat/www/python/venv/lib/python2.7/codecs", 0x7ffc2d0434f0) = -1 ENOENT (No such file or directory) <0.003500>
13:02:10.018539 open("/data/project/wdcat/www/python/venv/lib/python2.7/codecs.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003562>
13:02:10.022211 open("/data/project/wdcat/www/python/venv/lib/python2.7/codecs.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.002585>
13:02:10.024887 open("/data/project/wdcat/www/python/venv/lib/python2.7/codecsmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.003341>
13:02:10.028322 open("/data/project/wdcat/www/python/venv/lib/python2.7/codecs.py", O_RDONLY) = 4 <0.004150>where each stat()/open() call takes 3-7 ms. With
tools.wdcat@tools-bastion-03:~$ grep stracelog -e 'stat\|open' | wc -l 4294
calls, that's easily 15 seconds. Part of the issue is the large number of individual modules:
tools.wdcat@tools-bastion-03:~$ grep stracelog -e '[^f]stat\|open' | sed -e 's:.*/\([a-z\.]\):\1:' | sed -e 's:[\."].*::' | sort | uniq | wc -l 439
but the main difference is in the time stat() calls take. On the local disk, they are more than two orders of magnitude faster:
1464796893.470126 stat("/usr/lib/python2.7/dist-packages/flask/hashlib", 0x7ffe9f99f6b0) = -1 ENOENT (No such file or directory) <0.000014>
1464796893.470178 open("/usr/lib/python2.7/dist-packages/flask/hashlib.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory) <0.000011>In my memory, this used to be much faster. On toolsbeta-bastion it's slightly faster (7s instead of 15).
Using /data/scratch, I compared the performance between tools-bastion-03 and relic:
valhallasw@tools-bastion-03:/data/scratch/valhallasw$ time test/bin/python -c "import flask" real 0m10.785s user 0m0.269s sys 0m1.226s valhallasw@relic:/data/scratch/valhallasw$ time test/bin/python -c "import flask" real 0m1.492s user 0m0.136s sys 0m0.143s
tools-bastion-03: labstore.svc.eqiad.wmnet:/scratch on /data/scratch type nfs (rw,noatime,vers=4,bg,intr,sec=sys,proto=tcp,port=0,lookupcache=none,nofsc,hard) relic: labstore.svc.eqiad.wmnet:/scratch on /data/scratch type nfs (rw,noatime,vers=4,bg,hard,intr,sec=sys,proto=tcp,port=0,nofsc,addr=10.64.37.10,clientaddr=10.68.16.162)
It seems reasonable that the difference in lookupcache causes this:
If this option is not specified, or if all is specified, the client assumes both types of directory cache entries are valid until their parent directory's cached attributes expire.
This setting was introduced in 24399a9416c7b09d24942b6b2c548ccca4f7ac80 because of T106170: Attribute cache issue with NFS on Trusty.