A few questions about actor-framework

252 views
Skip to first unread message

John Bandela

unread,
Jul 30, 2015, 11:47:34 AM7/30/15
to actor-framework
I am using actor framework for a project I am working on. I am very impressed by it, and am actually reading Programming Erlang to be able to fully understand the actor model and idioms and use them in C++ with actor-framework.

I have a few questions.

1. What is the recommended way to return errors from actors messages? For example, I have an actor that basically wraps an array. I do not want a get_at_pos with an invalid pos to exit the actor, but want to return an error to the user. Is option a good thing to use for this?
2. How efficient is actor-framework at transmitting large messages? I am thinking about using actor-framework to sync 2 different machines. I would be sending vector<char> that could potentially be 100's of megabytes in size. Would actor-framework be able to handle this type of scenario efficiently?
3. Is there any way for send with incorrectly formed messages (ie messages that would be unhandled) to be flagged at compile time?
4. Does Visual C++ 2015 RTM, meet the requirements for C++11 compliance to be able to it with actor-framework? If so, do you have an estimate on how soon it will be supported by actor-framework


Thanks again for making such a nice framework. Actor-framework has truly been a pleasure to use so far. I really like how C++11 is multiparadigm and can support this model of concurrency so elegantly.

- John

Dominik Charousset

unread,
Jul 31, 2015, 6:04:55 AM7/31/15
to actor-f...@googlegroups.com
Hi,

... (I) am actually reading Programming Erlang to be able to fully understand the actor model and idioms and use them in C++ with actor-framework.

Erlang is a very good starting point, but of course made different decisions in some cases. There will be more tutorials and articles surrounding CAF in the future to make first steps into C++ actor programming easier.


3. Is there any way for send with incorrectly formed messages (ie messages that would be unhandled) to be flagged at compile time?
1. What is the recommended way to return errors from actors messages? For example, I have an actor that basically wraps an array. I do not want a get_at_pos with an invalid pos to exit the actor, but want to return an error to the user. Is option a good thing to use for this?

To answer your questions slightly out of order: CAF has two kinds of actors: statically typed and dynamically typed. You have probably already used the latter ones. The main difference is that statically typed actors use `typed_actor<...>` handles. Here is a small snippet that also is an example for your first question:


using array_actor = typed_actor<replies_to<uint32_t>
                                ::with_either<ok_atom, std::string>
                                ::or_else<error_atom, std::string>>;

array_actor::behavior_type array_actor_impl() {
  auto data = std::make_shared<std::vector<std::string>>();
  data->push_back("one");
  data->push_back("two");
  return {
    [=](uint32_t index) -> either<ok_atom, std::string>
                           ::or_else<error_atom, std::string> {
      if (index >= data->size())
        return {error_atom::value, "index out of bounds"};
      return {ok_atom::value, data->at(index)};
    }
  };
}

void some_function() {
  auto aut = spawn_typed(array_actor_impl);
  scoped_actor self;
  self->sync_send(aut, uint32_t{0}).await(
    [](ok_atom, const std::string& str) {
      assert(str == "one");
    },
    [](error_atom, const std::string& err) {
      std::cerr << "error: " << err << std::endl;
    }
  );
}


A pattern we often use in CAF for operations that might fail is to respond with either 'ok' or 'error' messages. In this particular case, optional<string> as result type is perfectly fine and will require less code an the caller side. If you copy & paste the example and play a bit around with it, you will see that the compiler will create errors for sending a wrong message to or expecting wrong results from the typed actor.


2. How efficient is actor-framework at transmitting large messages? I am thinking about using actor-framework to sync 2 different machines. I would be sending vector<char> that could potentially be 100's of megabytes in size. Would actor-framework be able to handle this type of scenario efficiently?

Communication between CAF nodes is binary, so there is no costly transformation on your data. The data will need to be copied to/from input/output buffers on the network layer, so chunking the data might still be a good idea.

4. Does Visual C++ 2015 RTM, meet the requirements for C++11 compliance to be able to it with actor-framework? If so, do you have an estimate on how soon it will be supported by actor-framework

Version 0.14 added first experimental support for MSVC [1]. Advanced match cases seem to be too advanced for the compiler, though, and it is very brittle (to say the least). For example, compiling the unit test for the typed actors causes an internal compiler error, while all occurrences in the actual code pass. The develop branch of CAF includes a fix for the IO library, so all "major" features of CAF *should* work by now. Feedback, testing, bugfixes, etc. for the MSVC build are highly welcome.

I am using actor framework for a project I am working on. I am very impressed by it (...) Thanks again for making such a nice framework. Actor-framework has truly been a pleasure to use so far.

It is always a pleasure to get feedback like this. :)

    Dominik


John Bandela

unread,
Jul 31, 2015, 9:47:04 AM7/31/15
to actor-framework, dominik.c...@haw-hamburg.de
Thanks for the answers. The with_either::or_else combined with typed_actors look like a very elegant way of error handling with the compiler making sure you handled the possible error.

 
There will be more tutorials and articles surrounding CAF in the future to make first steps into C++ actor programming easier.

Looking forward to it. Actor based programming is a new paradigm for me and I am looking to understand the "Design Patterns" of actor based programming.

Thanks again for the prompt and very helpful answers.

- John Bandela
 
Reply all
Reply to author
Forward
0 new messages