Paulus E. email@example.com wrote:
several tasks being carried out in parallel.
It’s not really similar. While my program executes several stages of
processing in parallel you are actually doing similar things in
At least that’s what I understood from your explanation and code.
In this particular
instance I download several pages using open-uri and output a chunk
to webrick as soon as its processing is finished (as responsiveness
is critical). For network I/O, ruby’s pseudo-threads seem to work
well, though I agree native threads would be much better.
True, as soon as slow IO is involved ruby threads do ok as long as the
processing doesn’t use too many resources.
Attached the ParallelEnumerate class along with a trivial test case.
Bear with me, it’s my first ruby script.
You try to tackle multithreading with your first script? Wow! I don’t
exactly understand why you use a thread per collection just to fill a
Maybe I’m missing something here but it looks a bit strange. Are you
this actually downloads in parallel?
If I would have done this I’d taken a different approach (but maybe I’m
missing some of your requirements): I’d create a queue which receives
(or whatever tasks you have). Then I’d set up n threads (n>0, probably
depending on user input) and each thread reads elements from the queue
processes them in parallel. You might as well combine both approaches,
if a URL has been downloaded, the content is pushed onto another queue
which another number of threads (possible just 1) reads and processes.