I recently started learning 0MQ . Earlier today I came across a blog, Python Multiprocessing with ZeroMQ . He talked about the fan drawing in the 0MQ manual that I read about, so he decided to give it a try.
Instead of just calculating the products of numbers by workers, as the source code does, I decided to try to get the fan to send large arrays to workers through 0mq messages. Below is the code that I used for my “experiments”.
As noted in the comment below, at any time when I tried to increase the string_length variable to a number greater than 3 MB, the code freezes.
Typical symptom: suppose we set string_length to 4 MB (i.e. 4194304), then perhaps the result manager receives the result from one worker, and then the code simply pauses. htop shows that 2 cores do not do much. The Etherape network traffic monitor also does not show traffic on the lo interface.
So far, after several hours, looking around, I could not understand what this is causing, and I would like to get a hint or two to the question of why and any solution on this issue. Thanks!
I am running Ubuntu 11.04 64bit on a Dell laptop with an Intel Core processor, 8 GB RAM, 80 GB Intel X25MG2 SSD, Python 2.7.1+, libzmq1 2.1.10-1chl1 ~ natty1, python-pyzmq 2.1.10-1chl1 ~ natty1
import time import zmq from multiprocessing import Process, cpu_count np = cpu_count() pool_size = np number_of_elements = 128 # Odd, why once the slen is bumped to 3MB or above, the code hangs? string_length = 1024 * 1024 * 3 def create_inputs(nelem, slen, pb=True): ''' Generates an array that contains nelem fix-sized (of slen bytes) random strings and an accompanying array of hexdigests of the former elements. Both are returned in a tuple. :type nelem: int :param nelem: The desired number of elements in the to be generated array. :type slen: int :param slen: The desired number of bytes of each array element. :type pb: bool :param pb: If True, displays a text progress bar during input array generation. ''' from os import urandom import sys import hashlib if pb: if nelem <= 64: toolbar_width = nelem chunk_size = 1 else: toolbar_width = 64 chunk_size = nelem