Akka.Cluster.Chunking 0.3.0

Prefix Reserved
dotnet add package Akka.Cluster.Chunking --version 0.3.0                
NuGet\Install-Package Akka.Cluster.Chunking -Version 0.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Akka.Cluster.Chunking" Version="0.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Akka.Cluster.Chunking --version 0.3.0                
#r "nuget: Akka.Cluster.Chunking, 0.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Akka.Cluster.Chunking as a Cake Addin
#addin nuget:?package=Akka.Cluster.Chunking&version=0.3.0

// Install Akka.Cluster.Chunking as a Cake Tool
#tool nuget:?package=Akka.Cluster.Chunking&version=0.3.0                

Akka.Cluster.Chunking

This is a plugin for Akka.NET that aims at making it easier to pass really large messages over Akka.Remote with minimal fuss.

Why?

With Akka.NET v1.5 and earlier - there's a famous problem with Large Messages and Sockets in Akka.Remote, namely that this renders the system vulnerable to "head of line blocking."

Akka.NET v1.6 and later will work around this issue via connection multiplexing, but since v1.5 and earlier use a single TCP connection between each node: head-of-line blocking is still a problem.

Enter Akka.Delivery - a new feature introduced in Akka.NET v1.5 that enables reliable delivery of messages between Akka.Remote nodes and supports "chunking" of large messages at the application layer in order to eliminate head-of-line blocking.

Akka.Delivery is very reliable and powerful, but it also requires deep integration between its messaging + actor management protocol and your application.

Akka.Cluster.Chunking is a turnkey solution for head-of-line blocking that uses Akka.Delivery and Akka.Cluster to automatically establish chunked message delivery between nodes - it just works via a tiny API.

If you have large (5mB+) messages that you need to deliver over Akka.Remote, this plugin is for you. Please note, however, that this plugin requires Akka.Cluster in order to run.

Use

To use, install the Akka.Cluster.Chunking NuGet package:

dotnet add package Akka.Cluster.Chunking

Configuration

To use Akka.Cluster.Chunking, you first need to configure the plugin and automatically start it:

We strongly recommend you use the Akka.Hosting APIs to configure Akka.Cluster.Chunking:

var host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((hostingContext, config) =>
    {
        config.AddJsonFile("appsettings.json", optional: false)
            .AddEnvironmentVariables();
    })
    .ConfigureServices((hostContext, services) =>
    {
        var akkaConfig = hostContext.Configuration.GetSection("AkkaConfiguration").Get<AkkaConfig>();
        services.AddAkka(akkaConfig.ActorSystemName, builder =>
        {
            builder
                .WithRemoting(akkaConfig.RemoteSettings)
                .WithClustering(akkaConfig.ClusterSettings)
                .AddChunkingManager() // MUST LAUNCH CHUNKING PLUGIN AT STARTUP ON ALL NODES
                .WithActors((system, registry, arg3) =>
            {
                system.ActorOf(Props.Create(() => new PrinterActor()), "printer");
                system.ActorOf(Props.Create(() => new SenderActor()), "sender");
            });
        });
    })
    .Build();
    
await host.RunAsync();
Using HOCON

To configure Akka.Cluster.Chunking via pure HOCON:

akka.cluster.chunking{
    # The size of the chunks used by Akka.Delivery between nodes
    chunk-size = 64kB
    
    # The maximum number of messages waiting to be chunked
    outbound-queue-capacity = 20
    
    # The maximum amount of time a message can be queued before it is dropped
    request-timeout = 5s
}

akka{
  extensions = ["Akka.Cluster.Chunking.ChunkingManagerExtension,Akka.Cluster.Chunking"]
  actor {
    serializers {
      cluster-chunking = "Akka.Cluster.Chunking.Serialization.ChunkingMessageSerializer, Akka.Cluster.Chunking"
    }

    serialization-bindings {
      "Akka.Cluster.Chunking.INetworkedDeliveryProtocol, Akka.Cluster.Chunking" = cluster-chunking
    }

    serialization-identifiers {
      "Akka.Cluster.Chunking.Serialization.ChunkingMessageSerializer, Akka.Cluster.Chunking" = 771
    }
  }
}

APIs

To deliver a chunked message from one remote endpoint to another, make the following API call:

// your method inside an Actor or elsewhere
public void UseChunked(ActorSystem system, object message, IActorRef recipient, IActorRef? sender = null){
    ChunkingManager chunker = ChunkingManager.For(system);

    // task completes once message is accepted by chunker, not when it's delivered
    await chunker.DeliverChunked(message, recipient, sender);
}

That's it - the message will be chunked over the network and delivered to the remote recipient and will be shown has having been sent by the IActorRef specified in the sender field.

Lifecycle

This plugin is currently an experiment and is available on an as-is basis.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 163 8/23/2024
0.2.0 630 8/14/2023
0.1.0 163 7/26/2023