Scaling Akka.Net












1















We use the Akka.net Framework for highly scaling applications in the energy sector.



We use Akka.net for various tasks, mostly in the following form:



var system=ActorSystem.Create("actorSystem");
var props=Props.Create<UpdateActor>();
.WithRouter(new SmallesMailboxPool(100));
var actorRef=system.ActorOf(props,"UpdateActor");
foreach(var timerow in timeRowList)
actorRef.Tell(timerow)


Unfortunately the Akka.net framework scales very badly in many cases.
The CPU load is only 12%.
Obviously only one thread or a few threads are used.



How can you configure Akka.Net to use multiple threads for processing the actors?










share|improve this question





























    1















    We use the Akka.net Framework for highly scaling applications in the energy sector.



    We use Akka.net for various tasks, mostly in the following form:



    var system=ActorSystem.Create("actorSystem");
    var props=Props.Create<UpdateActor>();
    .WithRouter(new SmallesMailboxPool(100));
    var actorRef=system.ActorOf(props,"UpdateActor");
    foreach(var timerow in timeRowList)
    actorRef.Tell(timerow)


    Unfortunately the Akka.net framework scales very badly in many cases.
    The CPU load is only 12%.
    Obviously only one thread or a few threads are used.



    How can you configure Akka.Net to use multiple threads for processing the actors?










    share|improve this question



























      1












      1








      1


      1






      We use the Akka.net Framework for highly scaling applications in the energy sector.



      We use Akka.net for various tasks, mostly in the following form:



      var system=ActorSystem.Create("actorSystem");
      var props=Props.Create<UpdateActor>();
      .WithRouter(new SmallesMailboxPool(100));
      var actorRef=system.ActorOf(props,"UpdateActor");
      foreach(var timerow in timeRowList)
      actorRef.Tell(timerow)


      Unfortunately the Akka.net framework scales very badly in many cases.
      The CPU load is only 12%.
      Obviously only one thread or a few threads are used.



      How can you configure Akka.Net to use multiple threads for processing the actors?










      share|improve this question
















      We use the Akka.net Framework for highly scaling applications in the energy sector.



      We use Akka.net for various tasks, mostly in the following form:



      var system=ActorSystem.Create("actorSystem");
      var props=Props.Create<UpdateActor>();
      .WithRouter(new SmallesMailboxPool(100));
      var actorRef=system.ActorOf(props,"UpdateActor");
      foreach(var timerow in timeRowList)
      actorRef.Tell(timerow)


      Unfortunately the Akka.net framework scales very badly in many cases.
      The CPU load is only 12%.
      Obviously only one thread or a few threads are used.



      How can you configure Akka.Net to use multiple threads for processing the actors?







      c# akka.net






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 16:54









      Amy

      21.6k1874131




      21.6k1874131










      asked Nov 21 '18 at 16:04









      kkleebergerkkleeberger

      84




      84
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This is an educated guess, but if you're using SmallestMailboxPool, keep in mind that it works pretty badly with non-blocking I/O and terribly with stashing.



          First thing is usually to check, if there are no blocking operations (like synchronous I/O, calling AsyncMethod().Result or Thread.Sleep), which will block current thread, effectively preventing it from being used by other actors.



          Another issue is very specific to smallest mailbox router, and it's related to stashing and persistent actors.



          Stashing



          Stashing is one of the popular ways to work with multi-step operations. This pattern can be represented as bellow.



            public class MyActor : ActorBase, IWithUnboundedStash
          {
          public IStash Stash { get; set; }

          public Receive Active(State workUnit) => message =>
          {
          switch(message)
          {
          case DoWork:
          // stash all messages not related to current work
          Stash.Stash(message);
          return true;
          case WorkDone done:
          // when current unit of work is done, unstash pending messages
          Stash.UnstashAll();
          Become(Idle);
          return true;
          }
          };

          public bool Idle(object message)
          {
          switch(message)
          {
          case DoWork work:
          StartWork(work.State);
          Become(Active(work.State)); //continue work in new behavior
          return true;
          default:
          return false;
          }
          }

          public bool Receive(object message) => Idle(message);
          }


          This case is pretty common i.e. persistent actors use it during their recovery process. Problem is that, it's cleaning up the mailbox, which gives SmallestMailbox routers a false sense that this actor's mailbox is empty, while in practice it's just stashing all incoming message.



          This is also a reason why peristent actors should not be routed using SmallestMailbox routers! Tbh. I cannot think of any scenario where putting persistent actors behind router of any kind is a valid option.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416051%2fscaling-akka-net%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This is an educated guess, but if you're using SmallestMailboxPool, keep in mind that it works pretty badly with non-blocking I/O and terribly with stashing.



            First thing is usually to check, if there are no blocking operations (like synchronous I/O, calling AsyncMethod().Result or Thread.Sleep), which will block current thread, effectively preventing it from being used by other actors.



            Another issue is very specific to smallest mailbox router, and it's related to stashing and persistent actors.



            Stashing



            Stashing is one of the popular ways to work with multi-step operations. This pattern can be represented as bellow.



              public class MyActor : ActorBase, IWithUnboundedStash
            {
            public IStash Stash { get; set; }

            public Receive Active(State workUnit) => message =>
            {
            switch(message)
            {
            case DoWork:
            // stash all messages not related to current work
            Stash.Stash(message);
            return true;
            case WorkDone done:
            // when current unit of work is done, unstash pending messages
            Stash.UnstashAll();
            Become(Idle);
            return true;
            }
            };

            public bool Idle(object message)
            {
            switch(message)
            {
            case DoWork work:
            StartWork(work.State);
            Become(Active(work.State)); //continue work in new behavior
            return true;
            default:
            return false;
            }
            }

            public bool Receive(object message) => Idle(message);
            }


            This case is pretty common i.e. persistent actors use it during their recovery process. Problem is that, it's cleaning up the mailbox, which gives SmallestMailbox routers a false sense that this actor's mailbox is empty, while in practice it's just stashing all incoming message.



            This is also a reason why peristent actors should not be routed using SmallestMailbox routers! Tbh. I cannot think of any scenario where putting persistent actors behind router of any kind is a valid option.






            share|improve this answer




























              1














              This is an educated guess, but if you're using SmallestMailboxPool, keep in mind that it works pretty badly with non-blocking I/O and terribly with stashing.



              First thing is usually to check, if there are no blocking operations (like synchronous I/O, calling AsyncMethod().Result or Thread.Sleep), which will block current thread, effectively preventing it from being used by other actors.



              Another issue is very specific to smallest mailbox router, and it's related to stashing and persistent actors.



              Stashing



              Stashing is one of the popular ways to work with multi-step operations. This pattern can be represented as bellow.



                public class MyActor : ActorBase, IWithUnboundedStash
              {
              public IStash Stash { get; set; }

              public Receive Active(State workUnit) => message =>
              {
              switch(message)
              {
              case DoWork:
              // stash all messages not related to current work
              Stash.Stash(message);
              return true;
              case WorkDone done:
              // when current unit of work is done, unstash pending messages
              Stash.UnstashAll();
              Become(Idle);
              return true;
              }
              };

              public bool Idle(object message)
              {
              switch(message)
              {
              case DoWork work:
              StartWork(work.State);
              Become(Active(work.State)); //continue work in new behavior
              return true;
              default:
              return false;
              }
              }

              public bool Receive(object message) => Idle(message);
              }


              This case is pretty common i.e. persistent actors use it during their recovery process. Problem is that, it's cleaning up the mailbox, which gives SmallestMailbox routers a false sense that this actor's mailbox is empty, while in practice it's just stashing all incoming message.



              This is also a reason why peristent actors should not be routed using SmallestMailbox routers! Tbh. I cannot think of any scenario where putting persistent actors behind router of any kind is a valid option.






              share|improve this answer


























                1












                1








                1







                This is an educated guess, but if you're using SmallestMailboxPool, keep in mind that it works pretty badly with non-blocking I/O and terribly with stashing.



                First thing is usually to check, if there are no blocking operations (like synchronous I/O, calling AsyncMethod().Result or Thread.Sleep), which will block current thread, effectively preventing it from being used by other actors.



                Another issue is very specific to smallest mailbox router, and it's related to stashing and persistent actors.



                Stashing



                Stashing is one of the popular ways to work with multi-step operations. This pattern can be represented as bellow.



                  public class MyActor : ActorBase, IWithUnboundedStash
                {
                public IStash Stash { get; set; }

                public Receive Active(State workUnit) => message =>
                {
                switch(message)
                {
                case DoWork:
                // stash all messages not related to current work
                Stash.Stash(message);
                return true;
                case WorkDone done:
                // when current unit of work is done, unstash pending messages
                Stash.UnstashAll();
                Become(Idle);
                return true;
                }
                };

                public bool Idle(object message)
                {
                switch(message)
                {
                case DoWork work:
                StartWork(work.State);
                Become(Active(work.State)); //continue work in new behavior
                return true;
                default:
                return false;
                }
                }

                public bool Receive(object message) => Idle(message);
                }


                This case is pretty common i.e. persistent actors use it during their recovery process. Problem is that, it's cleaning up the mailbox, which gives SmallestMailbox routers a false sense that this actor's mailbox is empty, while in practice it's just stashing all incoming message.



                This is also a reason why peristent actors should not be routed using SmallestMailbox routers! Tbh. I cannot think of any scenario where putting persistent actors behind router of any kind is a valid option.






                share|improve this answer













                This is an educated guess, but if you're using SmallestMailboxPool, keep in mind that it works pretty badly with non-blocking I/O and terribly with stashing.



                First thing is usually to check, if there are no blocking operations (like synchronous I/O, calling AsyncMethod().Result or Thread.Sleep), which will block current thread, effectively preventing it from being used by other actors.



                Another issue is very specific to smallest mailbox router, and it's related to stashing and persistent actors.



                Stashing



                Stashing is one of the popular ways to work with multi-step operations. This pattern can be represented as bellow.



                  public class MyActor : ActorBase, IWithUnboundedStash
                {
                public IStash Stash { get; set; }

                public Receive Active(State workUnit) => message =>
                {
                switch(message)
                {
                case DoWork:
                // stash all messages not related to current work
                Stash.Stash(message);
                return true;
                case WorkDone done:
                // when current unit of work is done, unstash pending messages
                Stash.UnstashAll();
                Become(Idle);
                return true;
                }
                };

                public bool Idle(object message)
                {
                switch(message)
                {
                case DoWork work:
                StartWork(work.State);
                Become(Active(work.State)); //continue work in new behavior
                return true;
                default:
                return false;
                }
                }

                public bool Receive(object message) => Idle(message);
                }


                This case is pretty common i.e. persistent actors use it during their recovery process. Problem is that, it's cleaning up the mailbox, which gives SmallestMailbox routers a false sense that this actor's mailbox is empty, while in practice it's just stashing all incoming message.



                This is also a reason why peristent actors should not be routed using SmallestMailbox routers! Tbh. I cannot think of any scenario where putting persistent actors behind router of any kind is a valid option.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 8:48









                Bartosz SypytkowskiBartosz Sypytkowski

                5,053925




                5,053925






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416051%2fscaling-akka-net%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga