# rust_vnpy_async_event_engine **Repository Path**: wangshaonan/rust_vnpy_async_event_engine ## Basic Information - **Project Name**: rust_vnpy_async_event_engine - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-11-24 - **Last Updated**: 2025-11-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 性能提升最多20%,主要是使用cpu多核心,可以订阅更多的交易品种 # Rust 版异步高性能高并发vnpy事件引擎项目完整安装指南 ## 1. 创建项目结构 ```bash # 创建项目目录 mkdir rust_async_event_engine_project cd rust_async_event_engine_project # 创建 src 目录 mkdir src ``` ## 2. 创建必要文件 ### 项目结构 ``` rust_async_event_engine_project/ ← 在这个目录下运行 maturin 命令 ├── Cargo.toml ← 配置文件 └── src/ └── lib.rs ← Rust 源代码 ``` ### 文件内容 **Cargo.toml** (放在 `rust_async_event_engine_project/` 目录下) ```toml [package] name = "rust_async_event_engine" version = "0.1.0" edition = "2021" [lib] name = "rust_async_event_engine" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.27", features = ["extension-module","chrono"] } tokio = { version = "1.48.0", features = ["full"] } chrono = "0.4.42" dashmap = "6.1.0" num_cpus = "1.17.0" futures = "0.3.31" [profile.release] opt-level = 3 lto = true codegen-units = 1 ``` **src/lib.rs** (放在 `rust_async_event_engine_project/src/` 目录下) ## 3. 安装依赖 ```bash # 确保已安装 Rust(如果没有) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env # 安装 maturin pip install maturin ``` ## 4. 编译和安装 ```bash # 在 rust_async_event_engine_project 目录下运行 cd rust_async_event_engine_project maturin build --release ``` **注意**:必须在包含 `Cargo.toml` 的目录下运行! ## 5. 测试 ```bash # 在 Python 中使用 修改vnpy/event/__init__.py代码如下 #from .engine import EVENT_TIMER, Event, EventEngine from rust_async_event_engine import EVENT_TIMER, Event, EventEngine ``` ## 6. 常见问题 ### 如果遇到 "command not found: maturin" ```bash pip install --user maturin # 或使用 pipx pipx install maturin ``` ### 如果遇到编译错误 ```bash # 更新 Rust rustup update stable # 清理并重新编译 cargo clean maturin build --release ``` ### 如果需要构建 wheel 包分发 ```bash # 在 rust_async_event_engine_project 目录下 maturin build --release # wheel 文件会生成在 target/wheels/ 目录 # 然后可以安装 pip install target/wheels/rust_async_event_engine-0.1.0-*.whl ``` ## 7. 完整操作示例 ```bash # 从零开始的完整流程 mkdir rust_async_event_engine_project && cd rust_async_event_engine_project mkdir src # 创建 Cargo.toml(复制上面的内容) cat > Cargo.toml << 'EOF' [package] name = "rust_async_event_engine" version = "0.1.0" edition = "2021" [lib] name = "rust_async_event_engine" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.27", features = ["extension-module","chrono"] } tokio = { version = "1.48.0", features = ["full"] } chrono = "0.4.42" dashmap = "6.1.0" num_cpus = "1.17.0" futures = "0.3.31" [profile.release] opt-level = 3 lto = true codegen-units = 1 # 创建 src/lib.rs(复制 artifact 的内容到这个文件) # 然后执行编译 maturin build --release # 测试 python3 -c "import rust_async_event_engine; print('安装成功!')" ``` ## 推荐配置速查 | 场景类型 | 典型应用 | BATCH\_SIZE |MAX\_CONCURRENCY | | :--- | :--- | :--- | :--- | | **通用/默认** | 混合逻辑,简单的计算 | **50 - 100** | **4 - 8** | | **CPU 密集型** | 复杂计算、数据处理、回测 | **200 - 500** | **1 - 2** (关键\!) | | **I/O 密集型** | 数据库写入、网络请求、API 调用 | **10 - 50** | **50 - 200** | | **低延迟/实时** | 高频交易信号、UI 交互 | **1 - 10** | **2 - 4** |