[racket] Racket and concurrency
On Tue, Jul 3, 2012 at 11:33 AM, Harry Spier <vasishtha.spier at gmail.com> wrote:
> I'm starting to look at Racket concurrency functions (futures and
> places) to increase the efficiency of my application and I have a few
> questions. Its an OCR application so that once I've segmented the
> text and created a data-structure to describe the text, the processing
> can be done concurrently at either higher or lower levels. I.e. I can
> process pages of a book concurrently, or I can process the pages
> sequentially and process lines on a page concurrently or again I can
> process lines sequentially but process letters concurrently.
>
> So my questions are:
> 1) Since there is no communication between my concurrent processes
> other than combining the results does it make more sense to use places
> rather than futures.
>
> 2) Is it better to do the concurrency at the highest level possible or
> at the lowest level possible. I.e. should I be processing pages
> concurrently or should I go to a much lower level and only be
> processing letters concurrently. Does it matter?
Assuming that you have multiple pages to process and that pages take
some non-trivial amount of time to process (seconds not milliseconds),
then making separate places to process pages seems like the right
starting point.
If you find you want to get to some lower-level granularity (if you're
seeing too much work still at the page level (ie only 4 pages on an 8
core machine), then you can then use futures inside the places to
break things up on a per-line or per-section of the page granularity.
> 3) How does hyperthreading affect the number of places or futures I
> can run concurrently? For example if I have an i7 with 4 cores and
> hyperthreading, will that run 4 or 8 places concurrently?
You can run as many as you want concurrently (more than the available
number of cores) but if you create too many, you'll lose your
parallelism. Assuming you've left hyperthreading enabled and you have
a good algorithm, you should see 8 things happening at once, tho.
> 4) Are there any "gotcha's" I need to look out for?
Lots, but that's true with any parallel programming endeavor. :) Keep
us posted here and let us know if you get stuck.
Robby