{"id":19773966,"url":"https://github.com/badoo/balancer","last_synced_at":"2025-04-30T18:32:39.483Z","repository":{"id":66759186,"uuid":"47427081","full_name":"badoo/balancer","owner":"badoo","description":"Load balancer that was presented at HighLoad++ 2015 Conference in Moscow","archived":false,"fork":false,"pushed_at":"2015-12-04T21:55:42.000Z","size":8,"stargazers_count":44,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-06T03:51:04.933Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badoo.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":"2015-12-04T20:25:36.000Z","updated_at":"2023-10-29T06:16:36.000Z","dependencies_parsed_at":"2023-05-21T09:15:50.360Z","dependency_job_id":null,"html_url":"https://github.com/badoo/balancer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fbalancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fbalancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fbalancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fbalancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badoo","download_url":"https://codeload.github.com/badoo/balancer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251761349,"owners_count":21639597,"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":[],"created_at":"2024-11-12T05:11:38.430Z","updated_at":"2025-04-30T18:32:38.989Z","avatar_url":"https://github.com/badoo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# balancer\nLoad balancer that was presented at HighLoad++ 2015 Conference in Moscow.\n\nThe load balancer is intended to fine-tune weights for upstream servers that you already have so that you get even balancing.\nIn order to use it, you must implement all abstract methods and call run() method.\nIf application exits with non-zero code then it means that something went wrong and you should see log for details.\n\nYou must implement the following methods:\n\n**getCurrentServerWeights:**\n\nParse your config file (see NginxBalancer class as an example) and return all current weights that you have in config.\n\n**updateServerWeights($new_weights, $to_delete):**\n\nUpdate weights for existing hosts in a config file and add new hosts into config as well (this information is provided by $new_weights variable).\nAlso delete hosts that are present in $to_delete section.\n\n**needCheckHTTP:**\n\nWhether or not you should check the HTTP heartbeat for hosts that you already have in you config file. If you return false then only new hosts will be checked with a heartbeat.\n\n**outputIsOk($hostname, $output):**\n\nFunction to check that HTTP output of a heartbeat request that was sent to $hostname is a correct one.\nIf you always return false here then no new hosts can be added.\n\n**getAliveHosts:**\n\nGet hosts that are alive using any central database you have (it is different from getCurrentServerWeights in a way that you actually provide the list of hosts from zabbix or something similar rather that hosts that are present in config file).\n\n**getCpuIdleStats($hostname):**\n\nReturn information about the host CPU usage, number of cores and also provide information on how long ago you received the information. The latter is necessary so that you do not try to make weights tuning based on stale data.\n\n**canDisableHosts($host_weights, $hosts_to_disable, \u0026$reason = ''):**\n\nWhether or not you can disable the provided number of hosts from balancing (useful only when needCheckHTTP returns true). It is suggested that you check peak CPU usage of your cluster without the provided hosts. An example implementation is provided in BaseBalancer class in comments.\n\n# Testing\nYou can see test for Base Balancer that can be seen at BaseBalancerTest.php. You run it as \"phpunit BaseBalancerTest.php\".\nThe test provides minimal implementation for an actual balancer and checks that basic functionality works using default settings.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadoo%2Fbalancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadoo%2Fbalancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadoo%2Fbalancer/lists"}