{"id":19337928,"url":"https://github.com/seipan/mylb","last_synced_at":"2025-04-23T01:31:08.870Z","repository":{"id":196913282,"uuid":"697370595","full_name":"seipan/mylb","owner":"seipan","description":"⭐ Implementing a Load Balancer in Golang(just a toy) ⭐","archived":false,"fork":false,"pushed_at":"2024-06-05T03:17:33.000Z","size":61,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T20:44:28.574Z","etag":null,"topics":["go","golang","load-balancer","load-balancing"],"latest_commit_sha":null,"homepage":"","language":"Go","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/seipan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-27T15:34:43.000Z","updated_at":"2023-10-10T02:27:27.000Z","dependencies_parsed_at":"2024-06-21T16:31:22.216Z","dependency_job_id":"4bb1238d-cee9-4a7e-b5e9-e2eab7673fbb","html_url":"https://github.com/seipan/mylb","commit_stats":null,"previous_names":["seipan/go-loadbalancer","seipan/mylb"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seipan%2Fmylb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seipan%2Fmylb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seipan%2Fmylb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seipan%2Fmylb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seipan","download_url":"https://codeload.github.com/seipan/mylb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250352228,"owners_count":21416459,"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":["go","golang","load-balancer","load-balancing"],"created_at":"2024-11-10T03:15:49.396Z","updated_at":"2025-04-23T01:31:08.436Z","avatar_url":"https://github.com/seipan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n![Last commit](https://img.shields.io/github/last-commit/seipan/mylb?style=flat-square)\n![Repository Stars](https://img.shields.io/github/stars/seipan/mylb?style=flat-square)\n![Issues](https://img.shields.io/github/issues/seipan/mylb?style=flat-square)\n![Open Issues](https://img.shields.io/github/issues-raw/seipan/mylb?style=flat-square)\n[![go](https://github.com/seipan/mylb/actions/workflows/go.yml/badge.svg)](https://github.com/seipan/loghook/actions/workflows/go.yml)\n[![testserver-e2e](https://github.com/seipan/mylb/actions/workflows/e2e-testserver.yml/badge.svg)](https://github.com/seipan/mylb/actions/workflows/e2e-testserver.yml)\n\n\u003cimg src=\"https://cdn-icons-png.flaticon.com/512/5880/5880629.png\" alt=\"eyecatch\" height=\"200\"\u003e\n\n# mylb\n\n⭐ Implementing a Load Balancer in Golang(just a toy)  ⭐\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n\u003c/div\u003e\n\n## Usage\n### testserver\nYou can launch servers for load balancer testing. There are a total of four servers.\n```\ncd testserver\nmake up\n```\nIf you want to restart the server, use the following command.\n```\ncd testserver\nmake re\n```\nThe four servers to be launched are as follows.\n```\nhttp://localhost:8081\nhttp://localhost:8082\nhttp://localhost:8083\nhttp://localhost:8085\nhttp://localhost:8086\nhttp://localhost:8087\nhttp://localhost:8088\nhttp://localhost:8089\n```\nThe responses from these APIs are as follows:\n```\n{\n\t\"message\": \"ok\",\n}\n```\nAmong these, 8081 and 8082 are set to wait 4 seconds before responding. This represents servers with slow responses.\n```go\nrouter.GET(\"/\", func(c *gin.Context) {\n\t\ttime.Sleep(4 * time.Second)\n\t\tc.JSON(200, gin.H{\n\t\t\t\"message\": \"ok\",\n\t\t})\n\t})\n```\n\n### loadbalancer\nThere are two types of load balancers in this repository, representing different algorithms.\nSpecifically, there are two types: lc (Least Connections) and lr (Least Response Time).The two types can be changed by modifying the config.json.\n\n```json:config.json\n{\n    \"type\": \"lr\"\n}\n```\nTo launch the load balancer, enter the following command. (Don't forget to start the test server beforehand.)\n```\nmake run\n```\n### Results\nLet's take a look at the actual execution results from here.\nFirst, let's take a look at the results for Least Connections.\n```\nmake run\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8081/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8081/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8082/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8083/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8083/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8081/\",\"connections\":0}\n```\nI think you can see that the server is actually being changed so that the connections become 0.\n\n\nNext, let's take a look at the results for Least Response Time.\n```\nmake run\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8085/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8085/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8085/\",\"connections\":0}\n{\"level\":\"info\",\"msg\":\"access to endpoint\",\"url\":\"http://localhost:8085/\",\"connections\":0}\n```\nNow, as explained earlier, you can see that there is no access to 8081 and 8082, which have slower responses.\n\n## Reference\n [Golangでロードバランサーを実装する](https://bmf-tech.com/posts/Golang%E3%81%A7%E3%83%AD%E3%83%BC%E3%83%89%E3%83%90%E3%83%A9%E3%83%B3%E3%82%B5%E3%83%BC%E3%82%92%E5%AE%9F%E8%A3%85%E3%81%99%E3%82%8B)\n\n  [Creating a Load Balancer in GO](https://medium.com/@leonardo5621_66451/building-a-load-balancer-in-go-1c68131dc0ef)\n\n https://github.com/kasvith/simplelb\n\n https://github.com/leonardo5621/golang-load-balancer\n\n\n\n ## License\nCode licensed under \n[the MIT License](https://github.com/seipan/mylb/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseipan%2Fmylb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseipan%2Fmylb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseipan%2Fmylb/lists"}