I was trying to use Hadoop's streaming pattern to use python code on a largish data set. However, uploading my data to the cluster actually takes approximately forever (I've not yet actually succeeded in doing so), and I'm sick of attempting to churn processes to keep my reservation active and all this other BS that is a waste of my time.
So, I decided to waste my time by writing my own little mini, single threaded map reduce functionality in python.
It is up and running and runs the scripts fine (though instead of using stdin/stdout, i'm passing things around with generators and such). However, one thing that I'm not very happy with is that as I'm sorting the data and caching it to disk (it is much too large to store all in memory at once), I am needing to convert from a python representation of the data (a sorted list of two tuples (key, value) pairs) to a flat file, forcing myself to write functions to convert to and from the flat file format back into the appropriate python representation. For merging the data, I just have a heap of tuples of the first (parsed) line of each file and the file handle, pop from the (min) heap, send the line to be processed, and replace that item in the heap with the next line from the file handle and the file handle itself.
What I'd rather do, if it is possible and faster, is have the python data be written as such, without the need to write converters for it. But, I don't want - can't, really -to read the entire file into memory at once. I'd rather just read each item from the cached list at a time.
Perhaps a bit of pseudo-Python will make this more clear:
with it being quite important that uncache being not too aggressive about reading forward into the file as I'll have some several thousand files open and caching all that will get expensive.
edit: If it wasn't obvious, I would basically want to do something like:
my_reducer(heapq.merge(uncache(x) for x in os.listdir(tmpfiles)))
So, I decided to waste my time by writing my own little mini, single threaded map reduce functionality in python.
It is up and running and runs the scripts fine (though instead of using stdin/stdout, i'm passing things around with generators and such). However, one thing that I'm not very happy with is that as I'm sorting the data and caching it to disk (it is much too large to store all in memory at once), I am needing to convert from a python representation of the data (a sorted list of two tuples (key, value) pairs) to a flat file, forcing myself to write functions to convert to and from the flat file format back into the appropriate python representation. For merging the data, I just have a heap of tuples of the first (parsed) line of each file and the file handle, pop from the (min) heap, send the line to be processed, and replace that item in the heap with the next line from the file handle and the file handle itself.
What I'd rather do, if it is possible and faster, is have the python data be written as such, without the need to write converters for it. But, I don't want - can't, really -to read the entire file into memory at once. I'd rather just read each item from the cached list at a time.
Perhaps a bit of pseudo-Python will make this more clear:
Code:
def cache(iterable, filename):
"""Write iterable to a new file located at filename"""
def uncache(filename):
for item in uncached.process(filename):
yield item
with it being quite important that uncache being not too aggressive about reading forward into the file as I'll have some several thousand files open and caching all that will get expensive.
edit: If it wasn't obvious, I would basically want to do something like:
my_reducer(heapq.merge(uncache(x) for x in os.listdir(tmpfiles)))