Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may be interested in a tiny piece of code I wrote: <a href="https://github.com/vmlaker/benchmark-sharedmem" rel="noreferrer">github.com/vmlaker/benchmark-sharedmem</a></p> <p>The only file of interest is <code>main.py</code>. It's a benchmark of <a href="https://bitbucket.org/cleemesser/numpy-sharedmem" rel="noreferrer">numpy-sharedmem</a> -- the code simply passes arrays (either <code>numpy</code> or <code>sharedmem</code>) to spawned processes, via Pipe. The workers just call <code>sum()</code> on the data. I was only interested in comparing the data communication times between the two implementations.</p> <p>I also wrote another, more complex code: <a href="https://github.com/vmlaker/sherlock" rel="noreferrer">github.com/vmlaker/sherlock</a>.</p> <p>Here I use the <a href="https://bitbucket.org/cleemesser/numpy-sharedmem" rel="noreferrer">numpy-sharedmem</a> module for real-time image processing with OpenCV -- the images are NumPy arrays, as per OpenCV's newer <code>cv2</code> API. The images, actually references thereof, are shared between processes via the dictionary object created from <a href="http://docs.python.org/2/library/multiprocessing.html#multiprocessing-managers" rel="noreferrer"><code>multiprocessing.Manager</code></a> (as opposed to using Queue or Pipe.) I'm getting great performance improvements when compared with using plain NumPy arrays.</p> <p><strong>Pipe vs. Queue</strong>:</p> <p>In my experience, IPC with Pipe is faster than Queue. And that makes sense, since Queue adds locking to make it safe for multiple producers/consumers. Pipe doesn't. But if you only have two processes talking back-and-forth, it's safe to use Pipe, or, as the docs read: </p> <blockquote> <p>... there is no risk of corruption from processes using different ends of the pipe at the same time.</p> </blockquote> <p><strong><code>sharedmem</code> safety</strong>:</p> <p>The main issue with <code>sharedmem</code> module is the possibility of memory leak upon ungraceful program exit. This is described in a lengthy discussion <a href="http://grokbase.com/t/python/python-list/1144s75ps4/multiprocessing-shared-memory-vs-pickled-copies" rel="noreferrer">here</a>. Although on Apr 10, 2011 Sturla mentions a fix to memory leak, I have still experienced leaks since then, using both repos, Sturla Molden's own on GitHub (<a href="https://github.com/sturlamolden/sharedmem-numpy" rel="noreferrer">github.com/sturlamolden/sharedmem-numpy</a>) and Chris Lee-Messer's on Bitbucket (<a href="https://bitbucket.org/cleemesser/numpy-sharedmem" rel="noreferrer">bitbucket.org/cleemesser/numpy-sharedmem</a>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload