{"id":17335364,"url":"https://github.com/shaovie/niubix","last_synced_at":"2025-08-22T13:03:52.863Z","repository":{"id":193575731,"uuid":"689076720","full_name":"shaovie/niubix","owner":"shaovie","description":"Just a reverse proxy service","archived":false,"fork":false,"pushed_at":"2023-09-25T02:55:33.000Z","size":568,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T18:50:35.621Z","etag":null,"topics":["high-performance","http-reverse-proxy","load-balancer","nginx-reverse-proxy","reverse-proxy"],"latest_commit_sha":null,"homepage":"","language":"C++","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/shaovie.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}},"created_at":"2023-09-08T18:37:06.000Z","updated_at":"2023-09-22T00:41:22.000Z","dependencies_parsed_at":"2023-09-08T20:47:53.073Z","dependency_job_id":"d4f57312-89c6-4713-8254-f23d1f8c4e59","html_url":"https://github.com/shaovie/niubix","commit_stats":null,"previous_names":["shaovie/niubix"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaovie/niubix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaovie%2Fniubix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaovie%2Fniubix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaovie%2Fniubix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaovie%2Fniubix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaovie","download_url":"https://codeload.github.com/shaovie/niubix/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaovie%2Fniubix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271643441,"owners_count":24795440,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"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":["high-performance","http-reverse-proxy","load-balancer","nginx-reverse-proxy","reverse-proxy"],"created_at":"2024-10-15T15:09:30.074Z","updated_at":"2025-08-22T13:03:52.798Z","avatar_url":"https://github.com/shaovie.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NiubiX\n\nJust a reverse proxy service\n\n实验性项目，NiubiX 只提供反向代理功能，持续完善中... (如有疑问可微信联系: shaoviea)\n\n与 Nginx/Haproxy 对比测试 Get/Post QPS可以达到3倍以上  \n\n测试环境:\n\u003e Linux 5.19.0-1030-gcp #32~22.04.1-Ubuntu  \n\u003e Instacne 1 GCP cloud VM, 2 cores, 4GB RAM 10.146.0.2 (nginx,haproxy, niubix run at here)   \n\u003e Instacne 2 GCP cloud VM, 2 cores, 4GB RAM 10.146.0.3 (backend, wrk run at here)  \n\n**nginx version config**\n```\nnginx version: nginx/1.24.0 (Ubuntu)\n\nupstream backend {\n\tserver 10.146.0.3:8080;\n\tkeepalive 16;\n}\nserver {\n\tlisten       8082 reuseport;\n\tserver_name  localhost;\n\n\taccess_log  off;\n\terror_log \toff;\n\n\tlocation / {\n\t\tproxy_pass http://backend;\n\t\tproxy_http_version 1.1;\n\t\tproxy_set_header Connection \"\";\n\t\tproxy_set_header X-Real-IP $remote_addr;\n\t\tproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\t}\n}\n\nroot         516       1  0 Aug24 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;\nwww-data  417322     516  0 12:13 ?        00:00:06 nginx: worker process\nwww-data  417323     516  0 12:13 ?        00:00:08 nginx: worker process\n```\n\n**haproxy version config**\n```\nHAProxy version 2.4.22-0ubuntu0.22.04.2 2023/08/14\n\nlisten niubix\n    bind 0.0.0.0:8083\n    mode http\n    option forwardfor\n    server s1 10.146.0.3:8080\n\nps -eLf | grep haproxy\nroot      449421       1  449421  0    1 15:11 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock\nhaproxy   449423  449421  449423  0    2 15:11 ?        00:00:05 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock\nhaproxy   449423  449421  449429  0    2 15:11 ?        00:00:05 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock\n```\n\n**单独测试后端程序处理能力, 确保不存在吞吐量瓶颈**\n```\nrun at 10.146.0.2\n\nwrk -t 2 -c 100 -d 10s  http://10.146.0.3:8080/xxx\nRunning 10s test @ http://10.146.0.3:8080/xxx\n  2 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   520.95us  203.98us   4.09ms   68.03%\n    Req/Sec    59.25k     2.68k   63.62k    52.50%\n  1179133 requests in 10.00s, 173.17MB read\nRequests/sec: 117888.45\nTransfer/sec:     17.31MB\n```\n\n连续测试数据\n```\n(base) root@instance-1:~# wrk -t 2 -c 100 -d 10s -H 'Connection: keep-alive' http://10.146.0.2:8081/niubix\nRunning 10s test @ http://10.146.0.2:8081/xxx\n  2 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     1.22ms  800.49us  19.71ms   94.57%\n    Req/Sec    26.67k     1.92k   29.53k    76.00%\n  530996 requests in 10.01s, 77.99MB read\nRequests/sec:  53032.21\nTransfer/sec:      7.79MB\n(base) root@instance-1:~# wrk -t 2 -c 100 -d 10s -H 'Connection: keep-alive' http://10.146.0.2:8082/nginx\nRunning 10s test @ http://10.146.0.2:8082/xxx\n  2 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    10.16ms   13.47ms  93.49ms   85.88%\n    Req/Sec     8.64k     7.59k   23.31k    68.50%\n  172028 requests in 10.01s, 26.41MB read\nRequests/sec:  17188.44\nTransfer/sec:      2.64MB\n(base) root@instance-1:~# wrk -t 2 -c 100 -d 10s -H 'Connection: keep-alive' http://10.146.0.2:8083/haproxy\nRunning 10s test @ http://10.146.0.2:8083/xxx\n  2 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     6.49ms    8.64ms 141.16ms   97.99%\n    Req/Sec     8.89k     1.25k   13.48k    85.86%\n  176005 requests in 10.00s, 21.82MB read\nRequests/sec:  17598.35\nTransfer/sec:      2.18MB\n```\n![](https://picx.zhimg.com/80/v2-80ddd7903e85bffbacb4c4b071241f01_1440w.png)\n\n```\n07:29:07.171557 IP 10.146.0.2.48798 \u003e 10.146.0.3.8080: Flags [.], ack 1, win 511, options [nop,nop,TS val 1952514973 ecr 3339282563], length 0\n\t0x0000:  4500 0034 614f 4000 4006 c44c 0a92 0002  E..4aO@.@..L....\n\t0x0010:  0a92 0003 be9e 1f90 553e 4bb9 90f5 ce3d  ........U\u003eK....=\n\t0x0020:  8010 01ff d9b0 0000 0101 080a 7461 039d  ............ta..\n\t0x0030:  c709 6883                                ..h.\n07:29:07.171651 IP 10.146.0.2.48798 \u003e 10.146.0.3.8080: Flags [P.], seq 1:135, ack 1, win 511, options [nop,nop,TS val 1952514973 ecr 3339282563], length 134: HTTP: GET /xxx HTTP/1.1\n\t0x0000:  4500 00ba 6150 4000 4006 c3c5 0a92 0002  E...aP@.@.......\n\t0x0010:  0a92 0003 be9e 1f90 553e 4bb9 90f5 ce3d  ........U\u003eK....=\n\t0x0020:  8018 01ff 1467 0000 0101 080a 7461 039d  .....g......ta..\n\t0x0030:  c709 6883 4745 5420 2f78 7878 2048 5454  ..h.GET./xxx.HTT\n\t0x0040:  502f 312e 310d 0a58 2d52 6561 6c2d 4950  P/1.1..X-Real-IP\n\t0x0050:  3a20 3130 2e31 3436 2e30 2e32 0d0a 582d  :.10.146.0.2..X-\n\t0x0060:  466f 7277 6172 6465 642d 466f 723a 2031  Forwarded-For:.1\n\t0x0070:  302e 3134 362e 302e 320d 0a48 6f73 743a  0.146.0.2..Host:\n\t0x0080:  2031 302e 3134 362e 302e 323a 3830 3831  .10.146.0.2:8081\n\t0x0090:  0d0a 5573 6572 2d41 6765 6e74 3a20 6375  ..User-Agent:.cu\n\t0x00a0:  726c 2f37 2e38 312e 300d 0a41 6363 6570  rl/7.81.0..Accep\n\t0x00b0:  743a 202a 2f2a 0d0a 0d0a                 t:.*/*....\n07:29:07.171661 IP 10.146.0.3.8080 \u003e 10.146.0.2.48798: Flags [.], ack 135, win 505, options [nop,nop,TS val 3339282564 ecr 1952514973], length 0\n\t0x0000:  4500 0034 9f4e 4000 4006 864d 0a92 0003  E..4.N@.@..M....\n\t0x0010:  0a92 0002 1f90 be9e 90f5 ce3d 553e 4c3f  ...........=U\u003eL?\n\t0x0020:  8010 01f9 154f 0000 0101 080a c709 6884  .....O........h.\n\t0x0030:  7461 039d                                ta..\n07:29:07.171808 IP 10.146.0.3.8080 \u003e 10.146.0.2.48798: Flags [P.], seq 1:155, ack 135, win 505, options [nop,nop,TS val 3339282564 ecr 1952514973], length 154: HTTP: HTTP/1.1 200 OK\n\t0x0000:  4500 00ce 9f4f 4000 4006 85b2 0a92 0003  E....O@.@.......\n\t0x0010:  0a92 0002 1f90 be9e 90f5 ce3d 553e 4c3f  ...........=U\u003eL?\n\t0x0020:  8018 01f9 15e9 0000 0101 080a c709 6884  ..............h.\n\t0x0030:  7461 039d 4854 5450 2f31 2e31 2032 3030  ta..HTTP/1.1.200\n\t0x0040:  204f 4b0d 0a43 6f6e 6e65 6374 696f 6e3a  .OK..Connection:\n\t0x0050:  206b 6565 702d 616c 6976 650d 0a53 6572  .keep-alive..Ser\n\t0x0060:  7665 723a 2067 6f65 760d 0a43 6f6e 7465  ver:.goev..Conte\n\t0x0070:  6e74 2d54 7970 653a 2074 6578 742f 706c  nt-Type:.text/pl\n\t0x0080:  6169 6e0d 0a44 6174 653a 2054 7565 2c20  ain..Date:.Tue,.\n\t0x0090:  3037 2053 6570 2035 3536 3636 2032 313a  07.Sep.55666.21:\n\t0x00a0:  3036 3a32 3520 474d 540d 0a43 6f6e 7465  06:25.GMT..Conte\n\t0x00b0:  6e74 2d4c 656e 6774 683a 2031 330d 0a0d  nt-Length:.13...\n\t0x00c0:  0a48 656c 6c6f 2c20 576f 726c 6421       .Hello,.World!\n```\n![](https://pica.zhimg.com/80/v2-d5ae358121a2c93e4544cbea1925a020_1440w.png?source=d16d100b)\ntcpdump tcp port 8080 抓包查看 niubix 实际数据，包含 X-Real-IP, XFF ，并且响应在微秒级\n\n#### 测试声明\n* niubix 仅提供反向代理功能\n* http parser 只解析反向代理需要的header\n* 只是初步测试, 并没有做冒烟测试和稳定性测试以及多条件下复杂测试\n* niubix 均衡策略使用的是 roundrobin(别的也还没实现呢), haproxy 也是一样的策略\n* backend 测试程序[code](https://github.com/shaovie/reactor/blob/main/example/techempower.cpp)\n* 功能逐步完善中, 基本框架是过硬的, 我相信这是一个好的开始\n\n## Development Roadmap\n\n- [x] Gracefully reload (like nginx reload)\n- [x] Health check\n- [x] Better HTTP parser\n- [x] GET/POST/DELETE/PUT/HEAD/ support\n- [x] Fronted active check\n- [x] Admin api\n- [x] Match app by host\n- [ ] More balance prolicy\n- [ ] Https\n- [ ] TCP protocol + Proxy Protocol\n- [ ] Transfer-Encoding: chunked\n- [ ] Finally, optimize memory\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaovie%2Fniubix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaovie%2Fniubix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaovie%2Fniubix/lists"}