Basic CAF questions

85 views
Skip to first unread message

Lari Karam

unread,
Apr 8, 2020, 11:41:20 AM4/8/20
to actor-framework
Hi everyone!

I'm still trying to wrap my head around the actor model and CAF, although a very slow progress I'm seeing lots of potential, specially for the project I'm working on.

I'm experimenting on building a scientific compute backend with the actor model. In short a calculator :) .
My goal is to provide the user the mathematical functions, blocks and operations and at runtime (through a UI or a parser) let them build the operations and pass the input data for compute.
For example:  c = cos(A) + log(B)
 _______         ___          _______         _____
|  cos(A)  |---->| +   |----->|  log(B)  | ---->|   C   |
|_______|       |___|        |_______|        |____|

The goal is that every mathematical block or operation is an independent module that the application can call and compose.

Before meeting CAF and the actor model, traditionally I would have gone for a directed acyclic graph with OOP... but where I'm blocked in the design now is how do I pass the user's data to CAF. So I've copied the typed_calculator example and like most examples they pass through a tester which is spawned in the caf_main function with a testee.

  • Can we pass arguments directly while spawning the actor without passing through a function?
i.e  system.spawn(typed_actor_addClass(A, B);
  • Can each block or operation have it's own system and CAF_MAIN function or it is better the integrate them into one that manages all the actor of the user session? Would there be a drawback in performance?
  • Can an event_based_actor Class have custom members and methods?
i.e
class Node : public event_based_actor {
public:
   
Node(actor_config& cfg, const string node_label) : event_based_actor(cfg),
                                                       label_
(node_label) {}
void setLabel(string newLabel){
        label_
= newLabel;
   
}

string label() -> string { return label_; }

protected:


behavior make_behavior
() override {
   
}

private:
   
string label_;
};


Sorry for the very basic questions and thanks in advance!

cheers

--
lari

Dominik Charousset

unread,
Apr 8, 2020, 3:27:00 PM4/8/20
to actor-f...@googlegroups.com
> Hi everyone!

Welcome to CAF! 🙂

> I'm experimenting on building a scientific compute backend with the actor model. In short a calculator :) .
> My goal is to provide the user the mathematical functions, blocks and operations and at runtime (through a UI or a parser) let them build the operations and pass the input data for compute.
> For example: c = cos(A) + log(B)
> _______ ___ _______ _____
> | cos(A) |---->| + |----->| log(B) | ---->| C |
> |_______| |___| |_______| |____|
>
> The goal is that every mathematical block or operation is an independent module that the application can call and compose.

Message passing isn’t terribly expensive, but it does have its price. If you send a message to have an actor compute cos(A), it’s probably cheaper to do the work in-place. Just pointing it out here. As long as cos/log were just some examples and your actual buildings blocks are more heavyweight then it’s probably going to be worth it.

> Before meeting CAF and the actor model, traditionally I would have gone for a directed acyclic graph with OOP... but where I'm blocked in the design now is how do I pass the user's data to CAF. So I've copied the typed_calculator example and like most examples they pass through a tester which is spawned in the caf_main function with a testee.
>
> • Can we pass arguments directly while spawning the actor without passing through a function?
> i.e system.spawn(typed_actor_addClass(A, B);

If you have implement your actor as a function: sys.spawn(my_fun, 1, 2, 3). If you have implemented your actor as a class: sys.spawn<my_class>(1, 2, 3). See https://actor-framework.readthedocs.io/en/0.17.4/Actors.html#spawning-actors.

> • Can each block or operation have it's own system and CAF_MAIN function or it is better the integrate them into one that manages all the actor of the user session? Would there be a drawback in performance?

It’s better to integrate them. Running multiple actor-systems in the same OS process can have some undesired side effects and running multiple OS processes usually only makes sense if you need a strong (i.e. segfault-safe) separation of some actors. Besides, spawning actors is the natural way actor applications scale. An actor has a couple hundred Bytes overhead (as opposed to several kB for a thread) and CAF allocates a thread pool for you that makes sure your actors use as many cores as possible.

> • Can an event_based_actor Class have custom members and methods?
> i.e
> class Node : public event_based_actor {
> public:
> Node(actor_config& cfg, const string node_label) : event_based_actor(cfg),
> label_(node_label) {}
> void setLabel(string newLabel){
> label_ = newLabel;
> }
>
> string label() -> string { return label_; }
>
> protected:
>
>
> behavior make_behavior() override {
> }
>
> private:
> string label_;
> };

Sure. But keep in mind that Node communicates to other actors via messages only. No calling of those member functions outside of the actor itself.

> Sorry for the very basic questions and thanks in advance!

No worries. Good luck with the project!

Dominik

Lari Karam

unread,
Apr 10, 2020, 3:22:40 PM4/10/20
to actor-framework
Thanks Dominik,

Yes they were some examples, the intention is use actors to compute over n-dimensional matrices, where the same operations can be independently calculated asynchronously.

So if I understand right, to call members of an actor class, we need another actor (i.e request_nodeLabel) which will get the member and output it? can the same actor send a message to it self and do this operation?

Thank you for taking the time to answer my questions.

cheers

--
Lari

Dominik Charousset

unread,
Apr 18, 2020, 2:05:55 PM4/18/20
to actor-f...@googlegroups.com
> Yes they were some examples, the intention is use actors to compute over n-dimensional matrices, where the same operations can be independently calculated asynchronously.
>
> So if I understand right, to call members of an actor class, we need another actor (i.e request_nodeLabel) which will get the member and output it? can the same actor send a message to it self and do this operation?

You’re not allowed to call members of another actor. You can send it a message and receive its response. This isolation is by design and allows CAF actors to communicate to other actors in a network-transparent way.

Actors can send messages to themselves. But an actor can of course just call member functions on itself. A common use case for sending yourself messages is time-based loops, where an actor wants to repeat a task every X seconds, for example.

> Thank you for taking the time to answer my questions.

You’re welcome. :)

Dominik
> --
> You received this message because you are subscribed to the Google Groups "actor-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to actor-framewo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/actor-framework/449f2033-1e9e-4374-99b1-d773982fa61f%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages