{"id":13393748,"url":"https://github.com/jiajunhuang/guard","last_synced_at":"2025-03-13T19:31:46.423Z","repository":{"id":57541520,"uuid":"118118065","full_name":"jiajunhuang/guard","owner":"jiajunhuang","description":"NOT MAINTAINED! A generic high performance circuit breaker \u0026 proxy server written in Go","archived":true,"fork":false,"pushed_at":"2018-08-18T08:04:33.000Z","size":180,"stargazers_count":739,"open_issues_count":1,"forks_count":36,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-01-17T15:57:28.994Z","etag":null,"topics":["circuit-breaker","proxy"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jiajunhuang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-19T11:37:03.000Z","updated_at":"2025-01-03T21:52:10.000Z","dependencies_parsed_at":"2022-09-14T16:41:22.360Z","dependency_job_id":null,"html_url":"https://github.com/jiajunhuang/guard","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiajunhuang%2Fguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiajunhuang%2Fguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiajunhuang%2Fguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiajunhuang%2Fguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jiajunhuang","download_url":"https://codeload.github.com/jiajunhuang/guard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243469204,"owners_count":20295709,"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":["circuit-breaker","proxy"],"created_at":"2024-07-30T17:00:59.723Z","updated_at":"2025-03-13T19:31:46.041Z","avatar_url":"https://github.com/jiajunhuang.png","language":"Go","funding_links":[],"categories":["Go","Go (531)"],"sub_categories":[],"readme":"# Guard\n\n[![Build Status](https://travis-ci.org/jiajunhuang/guard.svg?branch=master)](https://travis-ci.org/jiajunhuang/guard)\n[![codecov](https://codecov.io/gh/jiajunhuang/guard/branch/master/graph/badge.svg)](https://codecov.io/gh/jiajunhuang/guard)\n![GoReport](https://goreportcard.com/badge/github.com/jiajunhuang/guard)\n\nguard is a generic high performance circuit breaker \u0026 proxy written in Go. It has four major components:\n\n- radix tree \u0026 response status ring: which stores registered URLs\n- load balancer: which distributes requests(algorithms: randomized distribute, round robin, weighted round robin)\n- circuit breaker: which makes sure your backend services will not be broken down by a large quantity of requests\n- proxy server: it's based on fasthttp\n\n## Workflow\n\n![workflow diagram](./workflow.png)\n\n## Benchmark\n\nI've made a simple benchmark on my laptop(i5-3210M CPU @ 2.50GHz with 4 cores):\n\n```bash\n$ wrk --latency -H \"Host: www.example.com\" -c 2048 -d 30 -t 2 http://127.0.0.1:9999  # Nginx with 4 workers\nRunning 30s test @ http://127.0.0.1:9999\n  2 threads and 2048 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    99.62ms  158.44ms   1.36s    95.41%       \n    Req/Sec     6.43k     2.43k   11.36k    53.85%\n  Latency Distribution   \n     50%   58.34ms                                       \n     75%  153.81ms                                                         \n     90%  165.62ms                                                                               \n     99%  965.10ms                       \n  383670 requests in 30.09s, 311.00MB read\n  Socket errors: connect 1029, read 0, write 0, timeout 114\nRequests/sec:  12749.73                           \nTransfer/sec:     10.33MB                         \n\n$ wrk --latency -H \"Host: www.example.com\" -c 2048 -d 30 -t 2 http://127.0.0.1:23456  # guard with GOMAXPROCS=4\nRunning 30s test @ http://127.0.0.1:23456\n  2 threads and 2048 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    45.78ms   34.36ms   1.12s    89.09%\n    Req/Sec    11.35k     1.18k   14.19k    73.20%\n  Latency Distribution                                   \n     50%   41.87ms     \n     75%   56.55ms       \n     90%   74.52ms                                       \n     99%  111.06ms                                                         \n  676392 requests in 30.07s, 532.82MB read\n  Socket errors: connect 1029, read 0, write 0, timeout 0\nRequests/sec:  22494.06\nTransfer/sec:     17.72MB\n```\n\nFor now, guard's proxy performance is about ~~55% of Nginx~~ **1.76x** faster than Nginx,\nand **I'm still working on it! Don't worry, it will become better and better!**\n\nBy the way, ~~thanks the [suggestion](https://github.com/jiajunhuang/guard/issues/15) \nfrom [@dongzerun](https://github.com/dongzerun), by configure the `GOGC` in environment,\nguard's proxy performance is about 70% of Nginx.~~ guard does not allocate much memory now,\n`GOGC` does not make a change, but still say thanks to [@dongzerun](https://github.com/dongzerun)!\n\n## TODO\n\nmoved to https://github.com/jiajunhuang/guard/projects/1\n\n## Set it up\n\n1. build it using `go get -u`:\n\n```bash\n$ go get -u github.com/jiajunhuang/guard\n```\n\n2. start it\n\n```bash\n$ guard\n```\n\n3. now you need to register an application by send a POST request to `http://127.0.0.1:12345/app` with json like this:\n\n```json\n{\n    \"name\": \"www.example.com\",\n    \"backends\": [\"127.0.0.1:80\", \"127.0.0.1:80\", \"127.0.0.1:80\"],\n    \"weights\": [5, 1, 1],\n    \"ratio\": 0.3,\n    \"paths\": [\"/\"],\n    \"methods\": [\"GET\"],\n    \"fallback_type\": \"text\",\n    \"fallback_content\": \"hello world\"\n}\n```\n\nI'm doing it like this:\n\n```bash\n$ http POST :12345/app \u003c backends.json \nHTTP/1.1 200 OK\nContent-Length: 8\nContent-Type: text/plain; charset=utf-8\nDate: Sun, 21 Jan 2018 08:51:16 GMT\n\nsuccess!\n```\n\n4. and now, it works! whoops! try it:\n\n```bash\n$ http :23456 'Host: www.example.com'\nHTTP/1.1 200 OK\n...\n```\n\n5. by the way, you can inspect your configuration by visit http://127.0.0.1:12345/ :\n\n```bash\n$ http :12345\nHTTP/1.1 200 OK\nContent-Length: 235\nContent-Type: application/json\nDate: Fri, 26 Jan 2018 14:11:02 GMT\n\n{\n    \"apps\": {\n        \"www.example.com\": {\n            \"backends\": [\n                \"127.0.0.1:80\",\n                \"127.0.0.1:80\",\n                \"127.0.0.1:80\"\n            ],\n            \"disable_tsr\": false,\n            \"load_balance_method\": \"rr\",\n            \"methods\": [\n                \"GET\",\n                \"GET\"\n            ],\n            \"name\": \"www.example.com\",\n            \"paths\": [\n                \"/\",\n                \"/doc\"\n            ],\n            \"ratio\": 0.3,\n            \"weights\": [\n                5,\n                1,\n                1\n            ]\n        }\n    }\n}\n```\n\n## Changelogs\n\n- 2018-01-25: rewrite proxy from `net/http` to `fasthttp`, it's super fast now!\n- 2018-01-24: rewrite radix tree \u0026 statistics module, it's lock-free now!\n- 2018-01-22: add randomized distribute, naive round robin algorithms\n- 2018-01-21: rewrite status statistics module\n- 2018-01-20: guard works!\n- 2018-01-19: first commit\n\n## Thanks\n\n- [Golang](https://golang.org)\n- [fasthttp](https://github.com/valyala/fasthttp)\n- [httprouter](https://github.com/jiajunhuang/httprouter)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiajunhuang%2Fguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiajunhuang%2Fguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiajunhuang%2Fguard/lists"}