{"id":19036153,"url":"https://github.com/tx7do/test_libevent","last_synced_at":"2026-06-19T04:31:45.540Z","repository":{"id":38693139,"uuid":"506675805","full_name":"tx7do/test_libevent","owner":"tx7do","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-26T17:08:25.000Z","size":522,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T21:51:42.360Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/tx7do.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-23T14:34:43.000Z","updated_at":"2022-06-26T17:05:12.000Z","dependencies_parsed_at":"2022-08-30T22:11:48.985Z","dependency_job_id":null,"html_url":"https://github.com/tx7do/test_libevent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tx7do/test_libevent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Ftest_libevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Ftest_libevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Ftest_libevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Ftest_libevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tx7do","download_url":"https://codeload.github.com/tx7do/test_libevent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Ftest_libevent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34517748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-08T21:53:36.768Z","updated_at":"2026-06-19T04:31:45.524Z","avatar_url":"https://github.com/tx7do.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libevent 测试\r\n\r\n## IO模型\r\n\r\n### BIO（Blocking I/O）：阻塞I/O\r\n\r\n* 同步并阻塞\r\n* 一个连接一个线程\r\n* 适用于：连接数比较小且固定。\r\n* 流 I/O，以流的方式处理数据。\r\n\r\n### NIO（Non-Blocking IO）：非阻塞I/O\r\n\r\n* 同步非阻塞\r\n* 适用于：连接数目多且连接比较短。\r\n* 块 I/O，以块的方式处理数据。\r\n* 可实现一种模式：Reactor。\r\n* 内核将可读可写事件通知应用，由应用主动发起读写操作。\r\n\r\n### AIO（Asynchronous I/O）：异步I/O\r\n\r\n* 异步非阻塞\r\n* 适用于：连接数目多且连接比较长。\r\n* 块 I/O，以块的方式处理数据。\r\n* 可实现两种模式：Reactor 和 Proactor。\r\n* 内核将读完成事件通知应用，读操作由内核完成，应用只需操作数据即可；应用做异步写操作时立即返回，内核会进行写操作排队并执行写操作。\r\n\r\n## 线程模型\r\n\r\n### Reactor 单线程模型\r\n\r\n![单线程模型](./docs/reactor_single_thread_model.jpg)\r\n\r\n### Reactor 多线程模型\r\n\r\n![单线程模型](./docs/reactor_multithreading_model.jpg)\r\n\r\n### Reactor 主从多线程模型\r\n\r\n![单线程模型](./docs/master_slave_reactor_multithreading_model.jpg)\r\n\r\n## 安装依赖库\r\n\r\n```bash\r\nsudo apt install libevent-dev\r\nsudo apt install libfmt-dev\r\n```\r\n\r\n## 参考资料\r\n\r\n* [Netty's efficient reactor thread model](https://javamana.com/2021/09/20210909151058484V.html)\r\n* [彻底搞懂 netty 线程模型](https://www.cnblogs.com/luoxn28/p/11875340.html)\r\n* [libevent 线程池的设计](https://www.jianshu.com/p/d9e161acdd40)\r\n* [多线程使用libevent：那些花里胡哨的技巧](https://segmentfault.com/a/1190000040121458)\r\n* [libevent服务端，单线程应用](https://blog.csdn.net/c1s2d3n4cs/article/details/124255380)\r\n* [理解什么是BIO/NIO/AIO](https://segmentfault.com/a/1190000037714804)\r\n* [JAVA中BIO、NIO、AIO的分析理解](https://developer.aliyun.com/article/726698)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Ftest_libevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftx7do%2Ftest_libevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Ftest_libevent/lists"}