Scaling Akka.Net
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
add a comment |
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
add a comment |
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
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
c# akka.net
edited Nov 21 '18 at 16:54
Amy
21.6k1874131
21.6k1874131
asked Nov 21 '18 at 16:04
kkleebergerkkleeberger
84
84
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 8:48
Bartosz SypytkowskiBartosz Sypytkowski
5,053925
5,053925
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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