Memlink Runtime
Dynamic module loading and execution framework for Rust
Overview
Memlink Runtime is a high-performance dynamic module loading system that enables plugin architectures, hot-reloadable code, and safe FFI execution. Load shared libraries at runtime, call methods on them, and unload them without restarting your application.
Key Features
- ๐ Dynamic Loading - Load
.so,.dll,.dylibfiles at runtime - ๐ก๏ธ Panic Isolation - Module panics don't crash your application
- ๐ฅ Hot Reload - Replace modules with zero downtime
- ๐ Prometheus Metrics - Built-in observability
- ๐งต Thread-Safe - Concurrent module calls from multiple threads
- ๐ฆ Multi-Module - Load and manage multiple modules simultaneously
Quick Start
Installation
[]
= "0.1.0"
Basic Example
use ;
use ModuleRef;
Creating Modules
Modules are shared libraries that export three required functions:
Minimal Module (C)
int
int
int
Build Commands
| Platform | Command |
|---|---|
| Linux | cc -shared -fPIC -O2 -o my_module.so my_module.c |
| Windows | cl /LD my_module.c /Fe:my_module.dll |
| macOS | cc -shared -fPIC -O2 -o my_module.dylib my_module.c |
See ABI Documentation for full specification.
Advanced Usage
Loading Multiple Modules
use ;
use ModuleRef;
use Arc;
use thread;
let runtime = new;
// Load multiple modules
let math = runtime.load?;
let string = runtime.load?;
let crypto = runtime.load?;
// Call concurrently from different threads
let mut handles = vec!;
for in
for h in handles
Hot Reload
use ReloadConfig;
use Duration;
// Reload a module with new version
let config = default
.with_drain_timeout
.with_state_preservation;
let reload_state = runtime.reload_with_config?;
// Old module drains in-flight calls before unloading
Metrics and Monitoring
// Get usage statistics
let usage = runtime.get_usage.unwrap;
println!;
println!;
// Export Prometheus metrics
let metrics = new;
// ... after operations ...
println!;
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application โ
โ (Memlink Runtime) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Runtime โ
โ โโ Resolver (locate modules) โ
โ โโ Loader (load shared libs) โ
โ โโ Instance Manager (track loaded modules) โ
โ โโ Panic Handler (catch module panics) โ
โ โโ Metrics (Prometheus-compatible) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโ [module_a.so] โโ memlink_init/call/shutdown
โโโ [module_b.dll] โโ memlink_init/call/shutdown
โโโ [module_c.dylib] โโ memlink_init/call/shutdown
Components
| Component | Description |
|---|---|
| Runtime | High-level API for module management |
| Resolver | Locates and validates module files |
| Loader | Loads shared libraries and resolves symbols |
| Instance | Represents a loaded module |
| Arena | Fast bump allocator for module memory |
| Metrics | Collects and exports runtime statistics |
Performance
| Operation | Latency | Throughput |
|---|---|---|
| Module load | 92 ฮผs | - |
| Method call (64 bytes) | 210 ns | 4.7M calls/sec (single thread) |
| Module unload | 52 ฮผs | - |
| Hot reload | 237 ฮผs | - |
| Concurrent calls (8 threads) | - | 2.5M calls/sec |
| Memory overhead | 0.7 MB/module | - |
Key Highlights:
- โ Sub-microsecond call latency
- โ Linear scalability up to 8 threads
- โ Fast hot reload with zero downtime
- โ Low memory footprint
See Performance Benchmarks for detailed methodology, full results, and optimization recommendations.
Use Cases
Plugin Systems
Load user-created plugins without recompiling your application:
// Load all plugins from a directory
for entry in read_dir?
Hot-Reloadable Business Logic
Update logic in production without downtime:
// Watch for file changes
new?;
Sandboxed Execution
Isolate risky code that might panic:
// Module panics are caught and converted to errors
match runtime.call
API Reference
Core Traits
| Trait | Purpose |
|---|---|
ModuleRuntime |
Main interface for module operations |
ModuleResolver |
Resolve module references to artifacts |
Key Types
| Type | Description |
|---|---|
Runtime |
Default runtime implementation |
ModuleHandle |
Opaque handle to loaded module |
ModuleRef |
Module reference (path or registry) |
ModuleUsage |
Usage statistics per module |
ReloadState |
Tracks hot-reload operations |
Examples
Run the included examples:
# Multi-module concurrent calls
# Build test modules first (Linux/WSL)
See examples/modules/README.md for module documentation.
Platform Support
| Platform | Status | Extensions |
|---|---|---|
| Linux | โ Tested | .so |
| Windows | โ Tested | .dll |
| macOS | โ Tested | .dylib |
License
Memlink Runtime is licensed under the Apache License 2.0 (LICENSE-APACHE).
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Run
cargo testandcargo clippy - Submit a pull request
Development
# Build
# Test
# Lint
# Format
# Build docs
Related Crates
- memlink-shm - Shared memory IPC
- libloading - Underlying library loading
- dashmap - Concurrent hash map
Support
- Issues: GitHub Issues
- Documentation: docs.rs
- ABI Spec: docs/abi.md