Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.Actor: bounded IStash programmatic configuration #6661

Merged

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Apr 21, 2023

Changes

Other half of #6660 to address #6658 - adds the ability to configure the bounded stash size via Deploy and akka.actor.deployment in HOCON.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

@Aaronontheweb
Copy link
Member Author

Still a work in progress - haven't gotten tests and config parsing completely working yet.

@Aaronontheweb Aaronontheweb marked this pull request as ready for review April 24, 2023 17:08
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed all of my changes

@@ -843,6 +843,38 @@ The result of this is that when an actor is restarted, any stashed messages will
> [!NOTE]
> If you want to enforce that your actor can only work with an unbounded stash, then you should use the `IWithUnboundedStash` interface instead.

### Bounded Stashes

In certain scenarios, it might be helpful to put a limit on the size of the `IStash` inside your actor. You can configure a bounded stash via the following actor definition:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented how to configure a bounded stash with both Props and akka.actor.deployment here.

Either of these settings will configure the `IStash` to only have a maximum capacity of 2 items. If a third item is attempted to be stashed the `IStash` will throw a `StashOverflowException`.

> [!TIP]
> You can always check to see if your `IStash` is approaching its capacity by checking the `IStash.IsFull`, `IStash.Capacity`, or `IStash.Count` properties.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructed users how to check whether or not the bounded stash is becoming full here.

> [!TIP]
> You can always check to see if your `IStash` is approaching its capacity by checking the `IStash.IsFull`, `IStash.Capacity`, or `IStash.Count` properties.

If you attempt to apply a maximum stash capacity to an `IWithUnboundedStash` actor then the setting will be ignored.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caveat about applying this setting when using IWithUnboundedStash.

@@ -758,6 +758,38 @@ Note that the stash is part of the ephemeral actor state, unlike the mailbox. Th
> [!NOTE]
> If you want to enforce that your actor can only work with an unbounded stash, then you should use the `UntypedActorWithUnboundedStash` class instead.

### Bounded Stashes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy and paste from the ReceiveActor page - we should probably have a separate page on behavior-switching and stashing.

@@ -621,6 +621,7 @@ namespace Akka.Actor
public static readonly string NoDispatcherGiven;
public static readonly string NoMailboxGiven;
public static readonly Akka.Actor.Scope NoScopeGiven;
public const int NoStashSize = -1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This what IStash.Capacity has historically defaulted to when working with unbounded stashes - all I did was turn it into a constant.

@@ -122,7 +122,8 @@ public virtual Deploy ParseConfig(string key, Config config)
var router = CreateRouterConfig(routerType, deployment);
var dispatcher = deployment.GetString("dispatcher", "");
var mailbox = deployment.GetString("mailbox", "");
var deploy = new Deploy(key, deployment, router, Deploy.NoScopeGiven, dispatcher, mailbox);
var stashCapacity = deployment.GetInt("stash-capacity", -1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grab stash-capacity from HOCON

/// </remarks>
/// <param name="stashCapacity">The stash size to use when creating the actor.</param>
/// <returns>A new <see cref="Akka.Actor.Props" /> with the provided stash size..</returns>
public Props WithStashCapacity(int stashCapacity)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add overload for copying in StashCapacity without having to explicitly allocate a new Deploy each time (consistent with other settings.)

@@ -22,6 +22,8 @@ public UnboundedStashImpl(IActorContext context)
: base(context)
{
}

public override int Capacity => Deploy.NoStashSize; // stash must be unbounded
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnboundedStashImpl can't be set - it's always unbounded.

@@ -61,6 +61,7 @@ message DeployData {
string configManifest = 9;
int32 routerConfigSerializerId = 10;
string routerConfigManifest = 11;
int32 stashCapacity = 12;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition to wire format - if this value is missing then the stash defaults back to being unbounded.

# Specifies the stash capacity for an individual actor, when stashing is enabled.
# A default value of -1 is used to signify that this should be an _unbounded_ stash,
# which has no upper limit on storage capacity.
stash-capacity = -1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New reference for HOCON deployments.

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a few typo in the documentation

docs/articles/actors/receive-actor-api.md Outdated Show resolved Hide resolved
docs/articles/actors/untyped-actor-api.md Outdated Show resolved Hide resolved
@Arkatufus Arkatufus enabled auto-merge (squash) April 24, 2023 18:09
@Aaronontheweb Aaronontheweb disabled auto-merge April 24, 2023 19:37
@Aaronontheweb Aaronontheweb merged commit 1877a0e into akkadotnet:dev Apr 24, 2023
@Aaronontheweb Aaronontheweb deleted the fix-6658-boundedstash-config branch April 24, 2023 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants