简体   繁体   中英

Distribute heavy work between multiple grains (Microsoft Orleans)

I want to compute an easy parallelizable calculation (eg Mandelbrot) with Orleans on different grains parallel and merge the result back together once the grains are done. However, I am not sure how to do this or if Orleans is even the right framework for this kind of problem. Also let me mention that this won't be any project which will go in production, I am just playing around with Orleans.

Here is my idea so far: I have one graintype (let's call it "maingrain") which is an entry point for the client (might also be a grain). This grain then estimates the amount of needed processing power and divides the task into smaller parts which are distributed to other grains from another graintype (I will call these "subgrains"). It's no big deal to let these subgrains do the work and wait for a result which can be returned to the client, however I am not sure how to handle the subgrains.

Lets say, there is a call where I want to use 10 subgrains. I get each by a new GUID and let them work. They are done and the client gets the result. Now there is a call where I want to use X subgrains:

  • Should I simply activate X new subgrains with X new GUIDs and let the garbage collector do the cleanup?
  • Should I somehow reuse the previously activated subgrains (some kind of pooling) and how do I know that a subgrain is already reusable (=not busy)?
  • What happens, if I want to use multiple maingrains. Does each handle it's own subgrains?

How would you do it? Thank you.

You can mark the subgrain as "StatelessWorker" using the Orleans.Concurrency.StatelessWorkerAttribute. This will then automatically scale out the grain (create multiple instances of the same grain) when there's a backlog of messages in it's queue, allowing for these sub tasks to be processed in parallel.

Found this quite interesting regarding stateless workers: http://encloudify.blogspot.co.uk/2014/05/grains-grains-and-more-grains.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM