4

so I am thinking of using the actor model to solve a problem I currently have. For brevity, I have made up a scenario so we don't get too technical.

Lets say I have 3 benches but each bench supports a different amount of people:

  • Park Bench 1 supports 3 people simultaneously
  • Park Bench 2 supports 5 people simultaneously
  • Park Bench 3 supports 2 people simultaneously

Upfront I know which bench to route too however, what I don't have context of is how many people are sitting on the bench. What I want to do is block any further people from sitting on a bench if its full but when a seat becomes available allow them to sit on it.

For some reason, the Actor model popped into my head but I am not sure whether this is the correct approach and perhaps there is alternative approach to solving my problem in which case I am keen to hear.

I envision creating 3 actors ParkBench1Actor ParkBench2Actor ParkBench3Actor and somehow control the number of live actors. I believe concepts such as pooling can help in these scenarios http://getakka.net/articles/actors/routers.html#pools-vs-groups.

Would appreciate peoples thoughts on this and tell me whether I have lost the plot a little :)

  • As best I can see, Actor is not the correct approach. I would use a counting semaphore on each bench. I implemented one using a mutex and condition variable. These two primitives are available in all environments. A bit hard to grok, but it works. – user251748 Jan 30 '18 at 18:39
3

The actor model is distinguished from other techniques by virtue of its ability to run processes on any arbitrary machine within your computing domain. So if this capability fits your use case, then yes, it is ideal for your purposes.

However, a process is a relatively coarse-grained computational unit, and because of that, it's not appropriate for all scenarios. You wouldn't, for example, try to distribute the sorting of an ordinary array to actors unless the array was enormous. Instead, you would employ a finer-grained mechanism like threads and futures.

Map/Reduce engines like Hadoop/Hive (which take a big-data problem, break it into smaller pieces, fan it out to multiple machines and then perform an aggregation on the individual results) do justify a process-based, Actor-like model due to the huge amount of data involved.

  • My minimal knowledge of Actor is that it supports concurrency because each process has its own data and there is no interaction among processes, correct? I don't know how in this scenario the interaction of contending for limited resources would fit the Actor model. It seems to me that each 'bench' would need a counting semaphore (something I have implemented and used in the past). – user251748 Jan 30 '18 at 18:25
  • Well, each actor could be talking to a centralized database. The database has its own concurrency mechanisms. – Robert Harvey Jan 30 '18 at 18:33
  • That is illuminating. About 20 years ago I created a multi-threaded database transaction server shell, and it had a limited number of "thread slots" to handle requests coming in via HTTP. The only shared state I had to manage was the counting semaphore, and each thread talked to the database as though it was the only thread. If that is Actor, wow, I deserved a raise back then. I guess it is Actor. Hmm. – user251748 Jan 30 '18 at 18:43
  • There is a slight detail which is missing, in hindsight I should of added. The person on the bench will be making an external call to a third party (http) hence the need for blocking and controlling the number of actors in play. – Onam Jan 30 '18 at 18:59
  • I have to disagree with the first sentence. As Hewitt et al described it, there's no requirement that any of it be distributable across processes or systems. What differentiates the actor model is its notion that actors's behaviors are limited to spawning new actors, exchanging messages with other actors and modifying their own internal state. – Blrfl Feb 14 '18 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.