Introduction to the Hollywood Project
Hollywood is an ultra-fast actor engine specifically designed for speed and low-latency applications. This makes it an excellent choice for systems that need to handle a high volume of messages quickly, such as game servers, advertising brokers, and trading engines. Remarkably, Hollywood can process 10 million messages in under one second.
Understanding the Actor Model
The Actor Model, introduced by Carl Hewitt in 1973, is a computational model ideal for building highly concurrent and distributed systems. In this model, computation is handled by "actors," autonomous entities that communicate exclusively with message exchanges.
Each actor operates independently, maintaining its state and behavior, thereby making the system decentralized and fault-tolerant. If one actor fails, others can continue functioning unaffected. Actors can also be organized hierarchically, allowing for efficient management and error handling in complex systems.
Key Features of Hollywood
- Ensures message delivery even if an actor fails, utilizing a buffer mechanism.
- Supports both fire-and-forget and request-and-response messaging styles.
- Employs high-performance dRPC for seamless communication.
- Utilizes optimized protobufs without using reflection, boosting performance.
- Lightweight and highly customizable to fit specific use cases.
- Supports clustering, allowing for self-discovering distributed actors.
Performance Benchmarks
Hollywood's performance is evident in its ability to handle millions of messages effectively. During benchmarks, Hollywood was able to send over 3 million messages per second, maintaining concurrency without any dead letters.
Installation Process
To integrate Hollywood into your project, simply use the following Go command:
go get github.com/anthdm/hollywood/...
Note that Hollywood requires Golang version 1.21
to function properly.
Getting Started: Hello World Example
To get a feel for Hollywood, start with a simple setup:
-
Create an Engine: The core component responsible for managing actors and messages.
engine, err := actor.NewEngine(actor.NewEngineConfig())
-
Spawn an Actor: Initiate an actor, known as a receiver in Hollywood, to perform specific tasks.
pid := engine.Spawn(newHelloer, "hello")
-
Define Actor Behavior: Implement the
Receive
method to manage how the actor handles different messages.type helloer struct{} func (h *helloer) Receive(ctx *actor.Context) { switch msg := ctx.Message().(type) { case actor.Started: fmt.Println("hello world", msg.data) } }
-
Send a Message: Interact with the actor by sending messages.
engine.Send(pid, "hello world!")
Advanced Actor Features
- Spawning Actors: Provides flexibility in actor creation, including passing arguments to constructors.
- Remote Actors: Enables network-based communication between actors using Protobuf serialization for seamless data exchange.
- Eventstream Monitoring: Facilitates graceful error handling and monitoring by subscribing to system and custom events.
Customization and Extensibility
Hollywood supports various customizations, including adding middleware, custom logging, and remote actor configurations, allowing developers to tailor the engine to their specific needs.
Community and Support
Hollywood has an active community available on Discord. With over 2000 members, it's a valuable space for discussions, support, and sharing insights.
License
Hollywood is open-source and available under the MIT license, encouraging contributions and adaptations.
For detailed examples and further exploration, developers are encouraged to check out the examples directory and the Hollywood documentation.