protoactor-dotnet
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Top Related Projects
Canonical actor model implementation for .NET with local + distributed actors in C# and F#.
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
-
Install the NuGet package:
dotnet add package Proto.Actor
-
Create a simple actor:
using Proto; public class MyActor : IActor { public Task ReceiveAsync(IContext context) { // Handle messages here return Task.CompletedTask; } }
-
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);
-
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.
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð¬ Join our Slack channel
Proto.Actor
Ultra-fast, distributed, cross-platform actors.
Bootcamp Training
https://github.com/AsynkronIT/protoactor-bootcamp
Stats
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
Name | Role |
---|---|
Asynkron AB | Founder and owner of Proto.Actor |
Helleborg AS | Core contributor team |
Ubiquitous AS | Core contributor team |
Ahoy Games | Core contributor team |
Etteplan | Contributing tutorials, documentation |
Top Related Projects
Canonical actor model implementation for .NET with local + distributed actors in C# and F#.
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.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot