{"id":35198919,"url":"https://github.com/vistone/netconnpool-rust","last_synced_at":"2026-01-13T21:33:56.933Z","repository":{"id":328927216,"uuid":"1115763558","full_name":"vistone/netconnpool-rust","owner":"vistone","description":"A comprehensive, high-performance Rust network connection pool library with connection lifecycle management, health checks, and statistics monitoring. Supports TCP/UDP, IPv4/IPv6, fully thread-safe for high-concurrency scenarios.","archived":false,"fork":false,"pushed_at":"2025-12-31T05:47:09.000Z","size":45799,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-01T04:21:13.961Z","etag":null,"topics":["async","client-server","concurrent","connection-management","connection-pool","health-check","high-performance","ipv4","ipv6","network","network-programming","networking","pool","rust","rust-crate","rust-library","statistics","tcp","thread-safe","udp"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vistone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-13T14:01:19.000Z","updated_at":"2025-12-31T05:47:13.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vistone/netconnpool-rust","commit_stats":null,"previous_names":["vistone/netconnpool-rust"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/vistone/netconnpool-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistone%2Fnetconnpool-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistone%2Fnetconnpool-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistone%2Fnetconnpool-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistone%2Fnetconnpool-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vistone","download_url":"https://codeload.github.com/vistone/netconnpool-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistone%2Fnetconnpool-rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","client-server","concurrent","connection-management","connection-pool","health-check","high-performance","ipv4","ipv6","network","network-programming","networking","pool","rust","rust-crate","rust-library","statistics","tcp","thread-safe","udp"],"created_at":"2025-12-29T09:29:30.609Z","updated_at":"2026-01-13T21:33:56.928Z","avatar_url":"https://github.com/vistone.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NetConnPool - Rust 网络连接池管理库\n\n[![Rust](https://img.shields.io/badge/rust-1.92.0%2B-orange.svg)](https://www.rust-lang.org/)\n[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](LICENSE)\n[![Tests](https://img.shields.io/badge/tests-100%25_passing-brightgreen.svg)](#测试)\n\n一个功能全面、高性能的 Rust 语言网络连接池管理库，提供了完善的连接生命周期管理、健康检查、统计监控等功能。\n\n这是 [Go 版本 netconnpool](https://github.com/vistone/netconnpool) 的 Rust 实现，保持了相同的 API 接口和函数名。\n\n## 核心特性\n\n- 🚀 **高性能**：连接复用率 \u003e 95%，显著提升性能\n- 🔒 **并发安全**：完全线程安全，支持高并发场景\n- 🎯 **灵活配置**：支持客户端/服务器端两种模式\n- 📊 **详细统计**：提供丰富的统计信息，便于监控和优化\n- 🛡️ **自动管理**：健康检查、泄漏检测、自动清理\n- 🌐 **协议支持**：支持TCP/UDP，IPv4/IPv6\n- 🔄 **智能空闲池**：TCP/UDP 独立空闲池，避免协议混淆带来的性能抖动\n- 🪝 **生命周期钩子**：支持 Created/Borrow/Return 阶段的自定义回调\n\n## 安装\n\n在 `Cargo.toml` 中添加：\n\n```toml\n[dependencies]\nnetconnpool = \"1.0.4\"\n```\n\n或者从GitHub直接使用：\n\n```toml\n[dependencies]\nnetconnpool = { git = \"https://github.com/vistone/netconnpool-rust\", tag = \"v1.0.4\" }\n```\n\n## 快速开始\n\n### 客户端模式（默认）\n\n客户端模式用于主动连接到服务器的场景，适用于HTTP客户端、数据库客户端、RPC客户端等。\n\n```rust\nuse netconnpool::*;\nuse std::net::TcpStream;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // 创建客户端连接池配置\n    let mut config = default_config();\n    config.max_connections = 10;\n    config.min_connections = 2; // 预热2个连接（后台 best-effort）\n    \n    // 设置连接创建函数\n    config.dialer = Some(Box::new(|_protocol| {\n        TcpStream::connect(\"127.0.0.1:8080\")\n            .map(|s| ConnectionType::Tcp(s))\n            .map_err(|e| Box::new(e) as Box\u003cdyn std::error::Error + Send + Sync\u003e)\n    }));\n    \n    // 创建连接池\n    let pool = Pool::new(config)?;\n    \n    // 获取连接\n    let conn = pool.get()?;\n    \n    // 使用连接进行网络操作\n    if let Some(tcp_stream) = conn.tcp_conn() {\n        // ... 使用连接 ...\n    }\n    \n    // 归还连接：RAII 自动归还（drop 即可）\n    drop(conn);\n    \n    // 关闭连接池\n    pool.close()?;\n    \n    Ok(())\n}\n```\n\n### 服务器端模式\n\n服务器端模式用于接受客户端连接的场景，适用于HTTP服务器、TCP服务器等。\n\n```rust\nuse netconnpool::*;\nuse std::net::TcpListener;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // 创建监听器\n    let listener = TcpListener::bind(\"127.0.0.1:8080\")?;\n\n    // 创建服务器端连接池配置\n    let mut config = default_server_config();\n    config.listener = Some(listener);\n    config.max_connections = 100;\n\n    // 创建连接池\n    let pool = Pool::new(config)?;\n\n    // 获取连接（等待接受客户端连接）\n    let conn = pool.get()?;\n\n    // 使用连接处理客户端请求\n    if let Some(tcp_stream) = conn.tcp_conn() {\n        // ... 处理客户端请求 ...\n    }\n\n    // 归还连接：RAII 自动归还\n    drop(conn);\n\n    // 关闭连接池\n    pool.close()?;\n\n    Ok(())\n}\n```\n\n## API 文档\n\n主要 API（Rust 风格 snake_case）：\n\n- `Pool::new` - 创建新的连接池\n- `Pool::get` - 获取一个连接（自动选择协议/IP版本）\n- `Pool::get_ipv4` / `Pool::get_ipv6` - 获取指定 IP 版本连接\n- `Pool::get_tcp` / `Pool::get_udp` - 获取指定协议连接\n- `Pool::get_with_protocol` - 获取指定协议连接（可自定义超时）\n- `Pool::get_with_ip_version` - 获取指定 IP 版本连接（可自定义超时）\n- `Pool::get_with_timeout` - 获取连接（带超时）\n- `Pool::close` - 关闭连接池\n- `Pool::stats` - 获取统计信息\n\n连接归还采用 RAII：`PooledConnection` 在 `drop` 时自动归还到池中。\n\n## 测试\n\n### 运行单元测试\n\n```bash\ncargo test --lib\n```\n\n### 运行压力测试\n\n```bash\n# 运行所有压力测试\ncargo test --test stress_test -- --ignored --nocapture\n\n# 运行性能基准测试\ncargo test --test benchmark_test -- --ignored --nocapture\n\n# 运行集成测试\ncargo test --test integration_test -- --ignored --nocapture\n\n# 使用测试脚本运行所有测试\n./test/run_stress_tests.sh\n```\n\n### 运行特定测试\n\n```bash\ncargo test --lib test_pool_creation\n```\n\n## 项目结构\n\n```text\nnetconnpool-rust/\n├── src/                    # 源代码\n│   ├── lib.rs             # 库入口，导出所有公共 API\n│   ├── config.rs          # 配置结构和验证\n│   ├── connection.rs      # 连接封装和生命周期管理\n│   ├── errors.rs          # 错误定义\n│   ├── ipversion.rs       # IP 版本检测\n│   ├── mode.rs           # 连接池模式定义\n│   ├── pool.rs           # 核心连接池实现（包含健康检查和泄漏检测）\n│   ├── protocol.rs       # 协议类型检测\n│   ├── stats.rs          # 统计信息收集器\n│   └── udp_utils.rs      # UDP 工具函数\n├── test/                  # 测试文件（详见 test/README.md）\n│   ├── 单元测试/         # pool_test.rs, mode_test.rs, protocol_test.rs, ipversion_test.rs, stats_test.rs\n│   ├── 集成测试/         # integration_test.rs, test_server.rs\n│   ├── 压力测试/         # stress_test.rs, comprehensive_stress_test.rs, extreme_stress_test.rs, real_world_stress_test.rs\n│   ├── 模糊测试/         # fuzzing_client_test.rs, quick_fuzzing_test.rs\n│   ├── 性能测试/         # benchmark_test.rs, performance_test.rs, performance_report.rs\n│   ├── 统计模块测试/     # stats_stress_test.rs, stats_race_test.rs, stats_utilization_test.rs, idle_counts_cas_test.rs\n│   ├── 客户端-服务器测试/ # comprehensive_client_test.rs\n│   └── 测试脚本/         # run_*.sh, check_test_status.sh, monitor_stress_test.sh\n├── examples/              # 示例代码\n│   ├── basic_example.rs   # 基本使用示例\n│   ├── client_stress.rs  # 客户端压力测试示例\n│   └── server_example.rs # 服务器端示例\n├── docs/                  # 文档（详见 docs/README.md）\n│   ├── README.md         # 文档导航\n│   ├── STRUCTURE.md      # 项目结构说明\n│   ├── TEST_GUIDE.md     # 测试指南\n│   ├── SECURITY.md       # 安全审计报告\n│   ├── ANALYSIS.md       # 项目分析与改进建议\n│   └── ...              # 其他文档\n└── Cargo.toml            # 项目配置\n```\n\n详细的项目结构说明请参考 [docs/STRUCTURE.md](docs/STRUCTURE.md)\n\n## 版本\n\n当前版本：**1.0.4**\n\n## 许可证\n\nBSD-3-Clause License\n\n## 参考\n\n- [Go 版本 netconnpool](https://github.com/vistone/netconnpool)\n\n## 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n## 文档\n\n- **[文档导航](docs/README.md)** - 所有文档的索引和导航\n- **[贡献指南](CONTRIBUTING.md)** - 开发规范和贡献指南（**必读**）\n- **[项目结构](docs/design/STRUCTURE.md)** - 详细的代码组织结构\n- **[变更日志](docs/CHANGELOG.md)** - 版本变更历史\n- **[测试指南](docs/guides/TEST_GUIDE.md)** - 完整的测试指南\n- **[安全审计](docs/reports/SECURITY.md)** - 安全审计报告\n- **[项目分析](docs/reports/ANALYSIS.md)** - 项目分析与改进建议\n- **[测试说明](test/README.md)** - 如何运行和编写测试\n\n## 更新日志\n\n详见 [docs/CHANGELOG.md](docs/CHANGELOG.md)\n\n## 开发规范\n\n**重要：提交代码前请务必阅读 [CONTRIBUTING.md](CONTRIBUTING.md)**\n\n在提交代码到 GitHub 之前，必须运行：\n\n```bash\n# 运行完整检查\n./scripts/check_before_commit.sh\n```\n\n确保所有检查通过后才能提交。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvistone%2Fnetconnpool-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvistone%2Fnetconnpool-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvistone%2Fnetconnpool-rust/lists"}