Ice Croft
Ice Croft

Reputation: 29

Stateless or stateful C# actors

I'm designing a project which will activate and control many asynchronous actors simultaneously.

I'd like to ask, which approach should I use for more stability and scalability?

Stateless or stateful?

As far I as I see the difference, it looks like:

a. Stateful

Actor _act = new Actor (long key);

_act.DoSomething (object _what);

b. Stateless

Actor _act = new Actor (long key);

_act = _act.DoSomething(object _what);

As I know, second way is expensive - memory reservation, etc. But this one, second approach allows to don't bother about state and locks.

What way is preferable for dotnet? The goal number of actors to reach is about 100k, with 2.5-3 mils operations per second for one node.

PS Each actor has its finite-state machine to compute.

For stateful its called by periodic async delegate

For stateless its called on every operation in consideration of time dimension.

Upvotes: 2

Views: 813

Answers (1)

Jesse Carter
Jesse Carter

Reputation: 21147

The Actor Programming model is based around the idea that each Actor should be a unique and separate computational entity with self contained "state". It's hard to tell based on the code snippet that you've provided what benefits you might actually receive are by using one technique over the other but in my opinion at least you're somewhat defeating the very idea of Actors by not encapsulating their state in such a way that you can leverage things such as lock free code.

Upvotes: 1

Related Questions