user2350942
user2350942

Reputation:

Akka.net actor size

We are seeing Akka.net actors at around 2900 bytes each. (Akka.net v0.6.1.0)

Is this the approximate size for each actor in Akka.net ?

Program snippet

ActorSystem actor_system = ActorSystem.Create("myActor");//create an actor

     var greeter = actor_system.ActorOf<GreetingActor>("greeter");
     InternalActorRef[] greeterArray = new InternalActorRef[100000];

      for (int i = 0; i < greeterArray.Length; i++)
        {
          greeterArray[i] = actor_system.ActorOf<GreetingActor>("greeter" + i);
          Console.WriteLine("Creating Actor number " + i);
        }

Greeter

using Akka;
using Akka.Remote;
using Akka.slf4net;
using Akka.Actor;

namespace Akka_NET_test
{
    //Create the actor class
    public class GreetingActor : UntypedActor
    {       

        protected override void OnReceive(object message)
        {

         message
           .Match()
         //this can be done with "if (message is Greet)" if you prefer
           .With<Greet>(m => Console.WriteLine("Hello {0} from GreetingActor " +  this.Self.ToString(), m.myMsg));
        }
    }
}

Greet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Akka;
using Akka.Remote;
using Akka.slf4net;

namespace Akka_NET_test
{
    //Create a message type that your actor will respond to
    public class Greet
    {
        public string myMsg { get; set; }
    }
}

Sizes are reported as around 400 bytes/actor for Akka jvm and around 300 bytes/process for Erlang.

Spinning up 100,000 actors on the CLR in Akka.net seems to come in around 2900 bytes each.

Is that approximately correct?

Thanks in advance!

Upvotes: 4

Views: 2509

Answers (2)

Contango
Contango

Reputation: 80272

Actor size is now 400 bytes, which is comparable to Erlang which is 300-400 bytes.

Quote from www.getakka.net:

High Performance 50 million msg/sec on a single machine. Small memory footprint; ~2.5 million actors per GB of heap.

Upvotes: 5

Roger Johansson
Roger Johansson

Reputation: 23214

Akka.NET is probably a bit more heavy weight than it needs to be at the current stage.

For example:

  • Each element in an ActorPath currently have a complete copy of its prefix elements. so there is atleast some redundant bytes as strings and lists going on right there. (we have a task to refactor this)

  • ActorCell and it's related classes all use concurrent dictionaries to store child actorrefs, which will be inefficient memmory wise, we are working on porting the scala childcontainer trait.

So expect memory consumption to go down as we get closer to an 1.0 release.

What profiler did you use? e.g. if you are using windows task manager you are guaranteed to see incorrect numbers du to .NET's aggressive pre allocation for memory.

Also, have a look at the new ReceiveActor http://akkadotnet.github.io/wiki/ReceiveActor This doesn't use the message.Match().With(...) notation, and thus, will be lighter on the GC due to not allocating any pattern matching objects for each received message.

Upvotes: 9

Related Questions