{"id":24077357,"url":"https://github.com/findstr/silly","last_synced_at":"2025-04-30T08:11:06.383Z","repository":{"id":34261246,"uuid":"38146373","full_name":"findstr/silly","owner":"findstr","description":"A lightweight Lua game server framework. TCP,UDP,Websocket,gRPC,Redis,MySQL,prometheus,etcdv3.","archived":false,"fork":false,"pushed_at":"2025-04-30T01:28:58.000Z","size":4754,"stargazers_count":76,"open_issues_count":0,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-30T02:32:25.566Z","etag":null,"topics":["etcdv3","grpc","https","mysql","redis","tcp","tls","udp","websocket"],"latest_commit_sha":null,"homepage":"https://findstr.github.io/silly/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/findstr.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2015-06-27T04:13:38.000Z","updated_at":"2025-04-30T01:28:36.000Z","dependencies_parsed_at":"2024-01-13T11:29:32.447Z","dependency_job_id":"a86d101d-54d3-4f15-8967-f8568c4c14b9","html_url":"https://github.com/findstr/silly","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findstr%2Fsilly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findstr%2Fsilly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findstr%2Fsilly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findstr%2Fsilly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/findstr","download_url":"https://codeload.github.com/findstr/silly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666283,"owners_count":21624293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["etcdv3","grpc","https","mysql","redis","tcp","tls","udp","websocket"],"created_at":"2025-01-09T20:16:07.785Z","updated_at":"2025-04-30T08:11:06.377Z","avatar_url":"https://github.com/findstr.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"# Silly - 轻量级网络服务器框架\n\n[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/findstr/silly/blob/master/LICENSE)\n[![CI](https://github.com/findstr/silly/actions/workflows/ci.yml/badge.svg)](https://github.com/findstr/silly/actions/workflows/ci.yml)\n\n## Introduction | 简介\n\nSilly is a lightweight and minimalist server framework designed for efficient server-side development. It combines the performance of C with the flexibility of Lua, making it particularly suitable for game server development and other high-performance network applications.\n\nSilly 是一个轻量、极简的服务器程序框架。它将 C 语言的高性能与 Lua 的灵活性相结合，特别适合游戏服务器开发和其他高性能网络应用程序。\n\n## Example at a Glance | 代码一览\n\nHere is a simple example that demonstrates how to easily write an echo server with Silly to handle 100,000+ concurrent requests per second:\n\n这是一个简单的示例，展示了如何使用 Silly 轻松编写处理每秒 10w+ 并发请求的 echo server:\n\n```lua\nlocal tcp = require \"core.net.tcp\"\nlocal listenfd = tcp.listen(\"127.0.0.1:8888\", function(fd, addr)\n        print(\"accpet\", addr, fd)\n        while true do\n                local l = tcp.readline(fd, \"\\n\")\n                if not l then\n                        print(\"disconnected\", fd)\n                        break\n                end\n                tcp.write(fd, l)\n        end\nend)\n```\n\nTo run this echo server:\n\n运行这个echo server:\n\n```bash\n./silly echo_server.lua\n```\n\nTest with telnet or netcat:\n\n使用 telnet 或 netcat 测试：\n\n```bash\nnc localhost 8888\n```\n\n## Case | 案例\n\n[![](./docs/src/cases/case1.png)](https://www.taptap.cn/app/230552)\n\n## Core Features | 核心特性\n\n### Architecture | 架构设计\n- 🔧 **Hybrid Development** | **混合开发**\n  - Core components written in C for optimal performance\n  - Business logic implemented in Lua for rapid development\n  - 核心组件使用 C 语言开发，确保最佳性能\n  - 业务逻辑使用 Lua 实现，支持快速开发\n\n- 🧵 **Concurrency Model** | **并发模型**\n  - Single-process, single-thread model for business logic\n  - Eliminates complex multi-threading issues\n  - 业务逻辑采用单进程单线程模型\n  - 避免复杂的多线程问题\n\n- 🔄 **Asynchronous Programming** | **异步编程**\n  - Lua coroutines for clean asynchronous code\n  - No callback hell\n  - 使用 Lua 协程实现清晰的异步代码\n  - 避免回调地狱\n\n## System Architecture | 系统架构\n\n### Thread Model | 线程模型\n\n1. **Worker Thread** | **Worker 线程**\n   - Manages Lua VM and event processing\n   - Handles socket and timer events\n   - 管理 Lua 虚拟机和事件处理\n   - 处理 socket 和定时器事件\n\n2. **Socket Thread** | **Socket 线程**\n   - High-performance socket management (epoll/kevent/iocp)\n   - Configurable connection limit (default: 65535)\n   - 高性能 socket 管理（基于 epoll/kevent/iocp）\n   - 可配置连接限制（默认：65535）\n\n3. **Timer Thread** | **Timer 线程**\n   - High-resolution timer system\n   - Default: 10ms resolution, 50ms accuracy\n   - 高分辨率定时器系统\n   - 默认：10ms 分辨率，50ms 精度\n\n## Performance | 性能表现\n\n### Benchmark Results | 基准测试结果\nTest Environment | 测试环境：\n- CPU: Intel(R) Core(TM) i5-4440 @ 3.10GHz\n- Test Tool: redis-benchmark\n- 测试工具：redis-benchmark\n\n**PING_INLINE Test Results** | **PING_INLINE 测试结果**:\n```\n100000 requests completed in 0.76 seconds\n1000 parallel clients\n3 bytes payload\nkeep alive: 1\n\n0.00% \u003c= 2 milliseconds\n0.03% \u003c= 3 milliseconds\n70.15% \u003c= 4 milliseconds\n99.35% \u003c= 5 milliseconds\n99.70% \u003c= 6 milliseconds\n99.98% \u003c= 7 milliseconds\n100.00% \u003c= 7 milliseconds\n131926.12 requests per second\n```\n\n## Getting Started | 快速开始\n\n### Prerequisites | 前置要求\n\n#### Debian/Ubuntu\n```bash\napt-get install libreadline-dev\n```\n\n#### CentOS\n```bash\nyum install readline-devel\n```\n\n### Installation | 安装\n\n```bash\nmake\n```\n\n### Running | 运行\n\n```bash\n./silly \u003cmain.lua\u003e [options]\n```\n\n##### Available options | 可用选项:\n```\nCore Options | 核心选项:\n  -h, --help                Display this help message\n                            显示帮助信息\n  -v, --version             Show version information\n                            显示版本信息\n  -d, --daemon              Run as a daemon process\n                            以守护进程模式运行\nLogging Options | 日志选项:\n  -p, --logpath PATH        Specify log file path\n                            指定日志文件路径\n  -l, --loglevel LEVEL      Set logging level (debug/info/warn/error)\n                            设置日志级别 (debug/info/warn/error)\n  -f, --pidfile FILE        Specify PID file path\n                            指定 PID 文件路径\nLibrary Path Options | 库路径选项:\n  -L, --lualib_path PATH    Set Lua library path\n                            设置 Lua 库路径\n  -C, --lualib_cpath PATH   Set C Lua library path\n                            设置 C Lua 库路径\nCPU Affinity Options | CPU 亲和性选项:\n  -S, --socket_cpu_affinity Set CPU affinity for socket thread\n                            设置 socket 线程的 CPU 亲和性\n  -W, --worker_cpu_affinity Set CPU affinity for worker threads\n                            设置 worker 线程的 CPU 亲和性\n  -T, --timer_cpu_affinity  Set CPU affinity for timer thread\n                            设置 timer 线程的 CPU 亲和性\n```\n\n##### Custom Options | 自定义选项\n\nIn addition to the predefined options above, you can pass custom key-value pairs using the `--key=value` format. These values can be accessed in your Lua code using `require \"core.env\".get(key)`.\n\n除了上述预定义选项外，您可以使用 `--key=value` 格式传入自定义的键值对。这些值可以在 Lua 代码中通过 `require \"core.env\".get(key)` 来获取。\n\nExample | 示例:\n```bash\n# Start server with custom options | 使用自定义选项启动服务器\n./silly main.lua --port=8888 --max_connections=1000 --server_name=\"my_server\"\n```\n\nIn your Lua code | 在 Lua 代码中:\n```lua\nlocal env = require \"core.env\"\n\n-- Get custom options | 获取自定义选项\nlocal port = env.get(\"port\")              -- Returns \"8888\"\nlocal max_conn = env.get(\"max_connections\") -- Returns \"1000\"\nlocal name = env.get(\"server_name\")        -- Returns \"my_server\"\n\nprint(string.format(\"Starting %s on port %s with max connections %s\",\n    name, port, max_conn))\n```\n\n## Examples | 示例\n\n### Available Examples | 可用示例\n- [HTTP Server](examples/http.lua) | HTTP 服务器\n- [RPC System](examples/rpc.lua) | RPC 系统\n- [WebSocket Server](examples/websocket.lua) | WebSocket 服务器\n- [Timer Demo](examples/timer.lua) | 定时器演示\n- [Socket Programming](examples/socket.lua) | Socket 编程\n- [Patch System](examples/patch.lua) | 补丁系统\n\n### Running Examples | 运行示例\n\n单个示例 | Single example:\n```bash\nexamples/start.sh [http|rpc|websocket|timer|socket|patch]\n```\n\n所有示例 | All examples:\n```bash\nexamples/start.sh\n```\n\n## Development | 开发\n\n### Testing | 测试\n```bash\nmake testall\n```\n\n## Documentation | 文档\n\nFor detailed documentation, please visit our [Wiki](https://github.com/findstr/silly/wiki).\n\n详细文档请访问我们的 [Wiki](https://github.com/findstr/silly/wiki)。\n\n## License | 许可证\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindstr%2Fsilly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffindstr%2Fsilly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindstr%2Fsilly/lists"}