Expand description
The Kompact message-passing framework provides a hybrid approach between the Kompics component model and the Actor model for writing distributed systems.
To get all Kompact related things into scope import use kompact::prelude::*;
instead of use kompact::*;
.
Hello World Example
use kompact::prelude::*;
#[derive(ComponentDefinition, Actor)]
struct HelloWorldComponent {
ctx: ComponentContext<Self>
}
impl HelloWorldComponent {
pub fn new() -> HelloWorldComponent {
HelloWorldComponent {
ctx: ComponentContext::uninitialised()
}
}
}
impl ComponentLifecycle for HelloWorldComponent {
fn on_start(&mut self) -> Handled {
info!(self.ctx.log(), "Hello World!");
self.ctx().system().shutdown_async();
Handled::Ok
}
}
let system = KompactConfig::default().build().expect("system");
let component = system.create(HelloWorldComponent::new);
system.start(&component);
system.await_termination();
Crate Feature Flags
The following crate feature flags are available. They are configured in your Cargo.toml.
silent_logging
- Reduces logging to INFO in debug builds and ERROR in release builds
- Must be used with
--no-default-features
low_latency
- Prevents thread pool threads from going to sleep when using the default pool.
- This can improve reaction time to incoming network events, at the cost of much higher CPU utilisation.
ser_id_64
(default),ser_id_32
,ser_id_16
,ser_id_8
- Selects the bit-width of serialisation identifiers.
- Trying to use a serialisation id that is too large for the selected width will result in a compile-time error.
- All values are mutually exclusive and all but the default of
ser_id_64
must be used with--no-default-features
.
thread_pinning
- Enables support for pinning pool threads to CPU cores (or rather processing units).
- This flag has no effect if the runtime OS does not support thread pinning.
- Enabling this will cause as many threads as there are PUs to be pinned by default.
- Assignments can be customised by providing a custom scheduler with the desired settings.
- See executors crate for more details.
serde_support
(default)- Build with support for Serde serialisers.
type_erasure
(nightly-only)- Build with an experimental API for
dyn
type-erased components.
- Build with an experimental API for
use_local_executor
(default)- Use thread-local executors to avoid cloning the handle to the system scheduler for every component scheduling.
- Not all scheduler implementations support this feature, so you might have to disable it via
--no-default-features
if you are using a custom scheduler.
implicit_routes
(default)- Allow default broadcast and select actor paths on any node in the tree, not just where explicitly set via set_routing_policy.
- While this feature is convenient, it may open up your system to DoS attacks via broadcast on high-level nodes (e.g.
tcp://1.2.3.4:8000/*
). - If you are concered about this security risk, you can disable this feature by using
--no-default-features
.
Re-exports
pub use executors;
Modules
- Traits and structs for component API and internals
- Utilities for working with Kompact configuration keys and values
- All Kompact configuration keys
- Useful Kompact constants are re-exported in this module
- Default implementations for system components
- Helper structs and functions for doctests.
- Data structures for looking up the dispatch/routing table.
- Facilities and utilities for dealing with network messages Messaging types for sending and receiving messages between remote actors.
- Default networking implementation
- To get all kompact related things into scope import as
use kompact::prelude::*
. - A module containing helper functions for benchmarking
- A module containing helper functions for (unit) testing
- Facilities for routing messages
- Kompact system runtime facilities, such as configuration and schedulers
- Provides serialisation support for Serde
- Reusable timer facility internals
Macros
- ignore_controlDeprecatedA macro that provides an empty implementation of ComponentLifecycle for the given component
- A macro that provides an empty implementation of the required handler for the given
$port
on the given$component
- A macro that provides an empty implementation of ComponentLifecycle for the given component
- A macro that provides an empty implementation of the provided handler for the given
$port
on the given$component
- A macro that provides an implementation of ComponentLifecycle for the given component that logs the lifecycle stages at INFO log level.
- Macro to create config entries.
- A macro that provides a shorthand for an irrefutable let binding, that the compiler cannot determine on its own
- A macro to make matching serialisation ids and deserialising easier
Type Definitions
- A simple type alias Kompact’s slog
Logger
type signature. - A more readable placeholder for a stable Never (
!
) type.