Convert Figma logo to code with AI

asynkron logoprotoactor-dotnet

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin

1,706
285
1,706
92

Top Related Projects

Canonical actor model implementation for .NET with local + distributed actors in C# and F#.

23,940

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.

Quick Overview

Proto.Actor is an ultra-fast distributed actors framework for .NET, Go, and Java. It provides a platform for building concurrent and distributed systems using the actor model. Proto.Actor aims to be simple to use, fast, and scalable.

Pros

  • High performance and low latency due to its lightweight design
  • Supports multiple programming languages (C#, Go, Java)
  • Provides features for building distributed systems, including clustering and remote actors
  • Offers a simple and intuitive API for creating and managing actors

Cons

  • Less mature compared to some other actor frameworks like Akka.NET
  • Documentation could be more comprehensive, especially for advanced features
  • Limited ecosystem and third-party integrations compared to more established frameworks
  • Steeper learning curve for developers unfamiliar with the actor model

Code Examples

Creating a simple actor:

public class HelloActor : IActor
{
    public Task ReceiveAsync(IContext context)
    {
        if (context.Message is string msg)
        {
            Console.WriteLine($"Received: {msg}");
        }
        return Task.CompletedTask;
    }
}

Spawning an actor and sending a message:

var system = new ActorSystem();
var props = Props.FromProducer(() => new HelloActor());
var pid = system.Root.Spawn(props);

system.Root.Send(pid, "Hello, Proto.Actor!");

Using the scheduler to send periodic messages:

var system = new ActorSystem();
var props = Props.FromProducer(() => new HelloActor());
var pid = system.Root.Spawn(props);

system.Scheduler.SendRepeatedly(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), pid, "Tick");

Getting Started

  1. Install the NuGet package:

    dotnet add package Proto.Actor
    
  2. Create a simple actor:

    using Proto;
    
    public class MyActor : IActor
    {
        public Task ReceiveAsync(IContext context)
        {
            // Handle messages here
            return Task.CompletedTask;
        }
    }
    
  3. Set up the actor system and spawn an actor:

    var system = new ActorSystem();
    var props = Props.FromProducer(() => new MyActor());
    var pid = system.Root.Spawn(props);
    
  4. Send messages to the actor:

    system.Root.Send(pid, "Hello, Actor!");
    

Competitor Comparisons

Canonical actor model implementation for .NET with local + distributed actors in C# and F#.

Pros of Akka.NET

  • More mature and established ecosystem with extensive documentation
  • Wider adoption and larger community support
  • Better integration with .NET ecosystem and tooling

Cons of Akka.NET

  • Steeper learning curve due to more complex API and concepts
  • Heavier memory footprint and potential performance overhead
  • Less flexible in terms of customization and extension

Code Comparison

Akka.NET:

public class MyActor : ReceiveActor
{
    public MyActor()
    {
        Receive<string>(message => Console.WriteLine($"Received: {message}"));
    }
}

Proto.Actor:

public class MyActor : IActor
{
    public Task ReceiveAsync(IContext context)
    {
        if (context.Message is string message)
        {
            Console.WriteLine($"Received: {message}");
        }
        return Task.CompletedTask;
    }
}

Both frameworks implement the actor model for concurrent and distributed systems in .NET. Akka.NET offers a more comprehensive feature set and ecosystem, while Proto.Actor focuses on simplicity and performance. The code comparison shows that Proto.Actor uses a more straightforward approach with a single method for message handling, while Akka.NET employs a declarative style with message pattern matching.

23,940

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Pros of Dapr

  • Broader scope, covering multiple microservices patterns and building blocks
  • Language-agnostic, supporting multiple programming languages and frameworks
  • Strong community support and backing from Microsoft

Cons of Dapr

  • Steeper learning curve due to its comprehensive feature set
  • Requires additional infrastructure setup (Dapr sidecar)
  • May introduce some performance overhead compared to native implementations

Code Comparison

Dapr (using HTTP API):

var daprClient = new DaprClientBuilder().Build();
await daprClient.SaveStateAsync("statestore", "key", "value");

ProtoActor:

var props = Props.FromProducer(() => new MyActor());
var pid = Context.Spawn(props);
Context.Send(pid, new MyMessage());

Summary

Dapr is a more comprehensive microservices framework, offering a wide range of building blocks for distributed applications. It's language-agnostic and has strong community support. ProtoActor-dotnet, on the other hand, is specifically focused on the actor model in .NET, providing a lightweight and performant implementation. While Dapr offers more features, it may have a steeper learning curve and require additional setup. ProtoActor-dotnet is simpler to use for .NET developers but has a narrower scope.

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.

Pros of Service Fabric

  • Comprehensive distributed systems platform with built-in orchestration, scaling, and fault tolerance
  • Tight integration with Azure and other Microsoft technologies
  • Extensive documentation and enterprise-level support

Cons of Service Fabric

  • Steeper learning curve due to its complexity and breadth of features
  • Primarily designed for Windows and Azure environments, limiting cross-platform flexibility
  • Heavier resource footprint compared to lightweight actor frameworks

Code Comparison

Service Fabric (C#):

public class MyActor : Actor, IMyActor
{
    protected override Task OnActivateAsync()
    {
        ActorEventSource.Current.ActorMessage(this, "Actor activated.");
        return Task.CompletedTask;
    }
}

Proto.Actor (C#):

public class MyActor : IActor
{
    public Task ReceiveAsync(IContext context)
    {
        // Handle messages
        return Task.CompletedTask;
    }
}

Both frameworks use actor models, but Service Fabric provides a more comprehensive platform with additional features beyond just actor programming. Proto.Actor focuses on a lightweight, cross-platform actor model implementation, making it easier to adopt but with fewer built-in features compared to Service Fabric.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

💬 Join our Slack channel

Proto.Actor

Ultra-fast, distributed, cross-platform actors.

Bootcamp Training

https://github.com/AsynkronIT/protoactor-bootcamp

Stats

Alt

Installing

Using NuGet Package Manager Console:

PM> Install-Package Proto.Actor

Source code

This is the .NET repository for Proto Actor.

Other implementations:

Design principles

Minimalistic API - The API should be small and easy to use. Avoid enterprisey containers and configurations.

Build on existing technologies - There are already a lot of great technologies for e.g. networking and clustering. Build on those instead of reinventing them. E.g. gRPC streams for networking, Consul for clustering.

Pass data, not objects - Serialization is an explicit concern - don't try to hide it. Protobuf all the way.

Be fast - Do not trade performance for magic API trickery.

Getting started

The best place currently for learning how to use Proto.Actor is the examples. Documentation and guidance is under way, but not yet complete, and can be found on the website.

Hello world

Define a message type:

internal record Hello(string Who);

Define an actor:

internal class HelloActor : IActor
{
    public Task ReceiveAsync(IContext context)
    {
        var msg = context.Message;
        if (msg is Hello r)
        {
            Console.WriteLine($"Hello {r.Who}");
        }
        return Task.CompletedTask;
    }
}

Spawn it and send a message to it:

var system = new ActorSystem();
var context = system.Root;
var props = Props.FromProducer(() => new HelloActor());
var pid = context.Spawn(props);

context.Send(pid, new Hello("Alex"));

You should see the output Hello Alex.

Sample application

https://github.com/asynkron/realtimemap-dotnet

Contributors

Made with contributors-img.

Partners, Sponsors, and Contributor Companies

NameRole
Asynkron ABFounder and owner of Proto.Actor
Helleborg ASCore contributor team
Ubiquitous ASCore contributor team
Ahoy GamesCore contributor team
EtteplanContributing tutorials, documentation