[IPython-dev] pushAll and executeAll speed issue
fperez.net at gmail.com
Wed Nov 8 22:29:09 CST 2006
Brian will probably pitch in later with more comments, since he knows
the underbelly of this code better than I do. But in the meantime...
On 11/8/06, Albert Strasheim <fullung at gmail.com> wrote:
> Hello all
> I'm doing some experiments with IPython1 on Windows. I'm using DeinoMPI's
> GUI on top of mpi4py to start two kernels on my Core 2 Duo system. They
> connect to the controller without problems. I make a RemoteController and
> off I go. This is too cool.
> (By the way: as I understand it, MPI is currently only being used to start
> the kernels. From what I can see, it is not yet being used inside things
> like pushAll, etc. Is this the next step to use the MPI functions if they
> are available? Anybody working on this? If not, maybe I can try my hand at
> it. Any hints or suggestions on where to start appreciated.)
There is MPI code in there already, but currently it is not being used
for many core things. We should intelligently take advantage of it
when present, while gracefully falling back to pickle when MPI is not
> Anyway, back to my experiment. The script I'm using is attached.
> It starts off with some local benchmarks running on a single core. I get:
> cPickle dumps time 4.95649055955
> cPickle loads time 2.39126201794
> local map time 10.3841574837
> Then I push to all and time it. Here I get:
> total pushAll time 70.6287321433
> I was expecting something proportional to dumpsTime+N*loadsTime (if I
> understand correctly that it is serially pushing out the data to each of the
> N kernels) or maybe even less. I noticed that this section gets dramatically
> slower even with a relatively small increase in data size. While this is
> busy, I see Python using up all the CPU on one core as expected, but I also
> see that the Windows "System" process is very busy.
> Next up, the timing over the executeAll call that does the map:
> executeAll time for map 139.186242386
> but the kernels print:
> engine map time 12.8248084603
> engine map time 11.3900467797
> which is only slightly more than the single core time. However, I have to
> wonder where the heck the rest of the time went?! :-)
> Do you guys see similar timings on Linux? Any thoughts on where my time is
> going? Could it be Twisted? I tried with the latest from SVN and the
> official 2.4.0 release for Windows.
First, a numpy aside. Note that I had to change the original line
x = N.arange...
for x = range(), because otherwise I was getting zillions of
Warning: overflow encountered in long_scalars
It seems to come from this: numpy long scalars don't gracefully coerce
to Python longs:
In : x[-1]
In : x[-1]*x[-1]
Warning: overflow encountered in long_scalars
while the answer should be:
In : y=99999
In : y*y
But that's for the numpy list :)
Here's what is going on, most likely. The size of that enormous
pickled list is very large:
In : x = range(10000000)
In : len(cPickle.dumps(x))
That's a 100MB string, that needs to be shipped over the wire. At
this point, we are probably being hurt by Twisted, which makes
unnecessary copies of very large objects when transmitting them. I
know Brian and Min spent some time looking at this, but I'm not sure
how far they got; I think it wasn't too easy to fix directly, though
it /will/ need to be done eventually.
I see two possibilities:
a) Finding how to make Twisted-based sending of pickled strings as
efficient as possible, and with minimal copies.
b) Taking better advantage of MPI if available, so that the string
buffer is sent using MPI directly.
I see fairly similar results to yours:
In : run frags9.py
Connecting to controller: ('127.0.0.1', 10105)
cPickle dumps time 5.15
cPickle loads time 5.92
local map time 7.06
[127.0.0.1:0] In : import time
[127.0.0.1:1] In : import time
pushing to all...
total pushAll time 1.24
[127.0.0.1:0] In : t = time.clock()
[127.0.0.1:1] In : t = time.clock()
executing on all...
[127.0.0.1:0] In : z = map(lambda y:y*y, x)
[127.0.0.1:1] In : z = map(lambda y:y*y, x)
executeAll time for map 0.0
[127.0.0.1:0] In : t = time.clock() - t
[127.0.0.1:1] In : t = time.clock() - t
total time for push and execute 1.24
[127.0.0.1:0] In : print "engine map time", t
[127.0.0.1:0] Out: engine map time 7.16
[127.0.0.1:1] In : print "engine map time", t
[127.0.0.1:1] Out: engine map time 7.19
(0, 33, 'print "engine map time", t', 'engine map time 7.16\n', '')
(1, 26, 'print "engine map time", t', 'engine map time 7.19\n', '')
I also (under linux) saw an enormous amount of CPU usage from the
kernel; that's typical of large memory allocations being done.
Further, by the end of the runs my 2GB box was almost out of RAM.
For usage of read-only data in multicore machines, it would also be
nice to expose a shared-memory interface, but I'm not really up to
speed on the details of doing that, and whether Python exposes an API
to allow it to be done portably.
Basically, I think that we're starting to see where the performance
bottlenecks are. This is pre-alpha, after all ;)
We'll keep working on it...
More information about the IPython-dev