{"id":20917854,"url":"https://github.com/aceld/lars","last_synced_at":"2025-07-29T01:38:05.018Z","repository":{"id":108721211,"uuid":"206499221","full_name":"aceld/Lars","owner":"aceld","description":"负载均衡远程服务调度系统","archived":false,"fork":false,"pushed_at":"2023-08-03T08:18:47.000Z","size":43376,"stargazers_count":189,"open_issues_count":1,"forks_count":56,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-10T01:12:15.753Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/aceld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["aceld"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-09-05T07:13:39.000Z","updated_at":"2025-02-23T12:16:05.000Z","dependencies_parsed_at":"2023-10-20T16:18:38.353Z","dependency_job_id":null,"html_url":"https://github.com/aceld/Lars","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aceld/Lars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aceld%2FLars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aceld%2FLars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aceld%2FLars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aceld%2FLars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aceld","download_url":"https://codeload.github.com/aceld/Lars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aceld%2FLars/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267616866,"owners_count":24116170,"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-07-28T02:00:09.689Z","response_time":68,"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-18T16:36:10.959Z","updated_at":"2025-07-29T01:38:04.997Z","avatar_url":"https://github.com/aceld.png","language":"C","funding_links":["https://github.com/sponsors/aceld"],"categories":[],"sub_categories":[],"readme":"# \u003cimg width=\"80px\" src=\"https://s2.ax1x.com/2019/10/09/u4RfDf.png\" /\u003e \n\n(**L**oad balance **A**nd **R**emote service schedule **S**ystem)\n\n[![License](https://img.shields.io/badge/License-MIT%20-blue.svg)](LICENSE) [![Gitter](https://img.shields.io/badge/在线交流-Gitter-green.svg)](https://gitter.im/lars_cpp/community) [![Lars详细教程](https://img.shields.io/badge/Lars详细教程-简书-red.svg)](https://www.jianshu.com/p/ca3849716cd7)\n### 开发者\n* 刘丹冰([@aceld](https://github.com/aceld))\n* 王勇进([@MrWnag](https://github.com/MrWnag))\n---\n### Github\nGit: https://github.com/aceld/Lars\n\n### 码云(Gitee)\nGit: https://gitee.com/Aceld/Lars\n\n---\n\n\n# 一、系统开发环境:\n`Linux` : Ubuntu18.04\n\n`protobuf` : libprotoc 3.6.1版本及以上\n\n`mysql`: mysql  Ver 14.14 Distrib 5.7.27 版本及以上\n\n`g++`:  (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 版本及以上\n\n# 二、开发技术文档及教程\n[![Lars详细教程](https://img.shields.io/badge/Lars详细教程-语雀-green.svg)](https://www.yuque.com/aceld/wbs5h3/ggzqva)\n\n* Lars教程 各版本迭代代码:\n\nhttps://github.com/aceld/Lars_release\n\n\n### PC端文档\n\n* 语雀[《Lars-基于C++负载均衡远程服务器调度系统教程》](https://www.yuque.com/aceld/wbs5h3/ggzqva)\n\n* 看云 [《Lars-基于C++负载均衡远程服务器调度系统教程》](https://www.kancloud.cn/aceld/lars) \n\n![封面](https://upload-images.jianshu.io/upload_images/11093205-5f0b2c8f17dee274.png?imageMogr2/auto-orient/strip|imageView2/2/w/1010/format/webp)\n\n\n\n# 三、概述：\n\nLars是一个简单、易用、高性能的服务间远程调用管理、调度、负载均衡系统。\n\n## 1) 优势\n\n1. **性能强悍**\n\n   集群支持千万并发链接，满足用户的海量业务访问需求。\n\n2. **高可用**\n\n   采用集群化部署，支持多可用区的容灾，无缝实时切换。\n\n3. **灵活扩展**\n\n   自动分发，与弹性伸缩无缝集成，灵活扩展用户用于的对外服务能力。\n\n4. **简单易用**\n\n   快速部署、实时生效，支持多种协议，多种调度算法，用户可以高效的管理和调整服务分发策略等。\n\n\n\n## 2) 应用场景\n\n### (1)、大型门户网站\n\n​\t\t针对大型门户网站访问量高的特点，通过弹性负载均衡将用户的访问流量均匀的分发到多个后端云服务器上，确保业务快速平稳的运行\n\n#### 优势\n\n- 灵活扩展\n\n  可根据实际的用户访问量，自动扩展负载分发能力\n\n- 高性能\n\n  集群支持高并发连接，满足海量访问量诉求\n\n![Lars-1.png](https://ftp.bmp.ovh/imgs/2019/12/3be0e1bd1e73523a.png)\n\n### (2)、跨可用区同城容灾\n\n​\t\t弹性负载均衡可将流量跨可用区进行分发，建立实时的同城容灾机制，满足银行贸易等企业对系统的高可用性要求。\n\n#### 优势\n\n- 灵活扩展\n\n  可根据实际的用户访问量，自动扩展负载分发能力\n\n- 同城容灾\n\n  支持跨可用区的双活容灾，实现无缝实时切换\n\n\n![Lars-场景2.png](https://ftp.bmp.ovh/imgs/2019/12/bc530e9d1514ef94.png)\n\n\n\n### (3)、电商抢购\n\n​\t\t电商业务呈现出较强的潮汐效应。Lars通过和弹性伸缩等服务的无缝集成，自动创建后端云服务器，将流量自动分发到新的云服务器，缓解了促销高峰时期的系统压力。\n\n#### 优势\n\n- 弹性伸缩\n\n  根据业务流量实时创建或移除云服务器\n\n- 高可用\n\n  通过健康检查快速屏蔽异常云服务器，确保业务高可用\n\n- 高性能\n\n  集群支持高并发连接，满足海量访问量诉求\n\n![Lars-场景3.png](https://ftp.bmp.ovh/imgs/2019/12/f370141ee37e00bb.png)\n\n## 3) Lars系统总体架构\n\n​\t\t对于一个部门的后台，为增强灵活性，一个服务可以被抽象为命令字：`modid+cmdid`的组合，称为**一个模块**，而这个服务往往有多个服务节点，其所有服务节点的地址集合被称为这个模块下的**路由**，节点地址简称为节点\n\n- `modid`：标识业务的大类，如：“直播列表相关”\n\n- `cmdid`：标识具体服务内容，如：“批量获取直播列表”\n\n  ​\t业务代码利用modid,cmdid，就可以调用对应的远程服务一个Lars系统包含一个DNSService，一个Report Service，以及部署于每个服务器的LoadBalance Agent，业务代码通过API与Lars系统进行交互\n\n**API** ：根据自身需要的`modid,cmdid`，向Lars系统获取节点、汇报节点调用结果；提供`C++`、`Golang`(开发中...)、`Python`(开发中...)接口\n\n**LoadBalance Agent**：运行于每个服务器上，负责为此服务器上的业务提供节点获取、节点状态汇报、路由管理、负载调度等核心功能\n\n**DNSService** ： 运行于一台服务器上（也可以用LVS部署多实例防单点），负责`modid,cmdid`到节点路由的转换\n\n**Report Service** ： 运行于DNSService同机服务器上，负责收集各`modid,cmdid`下各节点调用状况，可用于观察、报警\n\n`modid,cmdid`数据由`Mysql`管理，具体SQL脚本在`common/sql`路径下\n至于`modid,cmdid`的注册、删除可以利用Web端操作MySQL。\n\n![1-Lars-总体架构设计.png](https://ftp.bmp.ovh/imgs/2019/12/73f562dccbe08f45.png)\n\n\n如图，每个服务器（虚线）部署了一台LoadBalance Agent，以及多个业务服务\n\n1. 开发者在Web端注册、删除、修改`modid,cmdid`的路由信息，信息被写入到MySQL数据库；\n2. 服务器上每个业务biz都把持着自己需要通信的远程服务标识`modid+cmdid`，每个biz都向本机LoadBalance Agent获取远程节点，进而可以和远程目标服务通信，此外业务模块会汇报本次的节点调用结果给LoadBalance Agent；\n3. LoadBalance Agent负责路由管理、负载均衡等核心任务，并周期性向DNSService获取最新的路由信息，周期性把各`modid,cmdid`的各节点一段时间内的调用结果传给Report Service\n4. DNSService监控MySQL，周期性将最新路由信息加载出来；\n5. Report Service将各`modid,cmdid`的各节点一段时间内的调用结果写回到MySQL，方便Web端查看、报警。\n\n# 四、快速开始\n## (1) 编译及安装\n**代码下载**\n```bash\n    git clone https://github.com/aceld/Lars.git\n```\n**编译**\n```bash\n    cd ./Lars\n    make\n```\n\n\u003e 注意：Lars依赖protobuf库，所以环境应该有protobuf环境，如果没有，可以参考下面文章进行安装\n\u003e https://mp.weixin.qq.com/s/c--hV7AXMKnbuUAm59_DvA\n\n\n## (2) 数据库配置\n**创建表**\n```bash\n    cd ./Lars/base/sql\n```\n    进入`mysql`，导入表`lars_dns.sql`文件\n```bash\n    mysql -u root -p\n    #输入密码\n```\n```bash\nmysql\u003e source ./lars_dns.sql\n```\n## (3) 各子系统配置文档\n**lars reporter**\n\u003e ./Lars/lars_reporter/conf/lars_reporter.conf \n```ini\n[reactor]\nmaxConn = 1024\nthreadNum = 5\nip = 127.0.0.1\nport = 7779\n\n[mysql]\ndb_host = 127.0.0.1\ndb_port = 3306\ndb_user = root\ndb_passwd = **Your PassWord**\ndb_name = lars_dns\n\n[repoter]\ndb_thread_cnt = 3    \n```\n\n\n**lars dns**\n\u003e ./Lars/lars_dns/conf/lars_dns.conf\n```ini\n[reactor]\nmaxConn = 1024\nthreadNum = 5\nip = 127.0.0.1\nport = 7778\n\n[mysql]\ndb_host = 127.0.0.1\ndb_port = 3306\ndb_user = root\ndb_passwd = **Your PassWord**\ndb_name = lars_dns\n```\n\n**lars LoadBalance Agent**\n\u003e ./Lars/lars_loadbalance_agent/conf/lars_lb_agent.conf\n```ini\n[reporter]\nip = 127.0.0.1\nport = 7779\n\n[dnsserver]\nip = 127.0.0.1\nport = 7778\n\n[loadbalance]\n\n;经过若干次获取请求host节点后，试探选择一次overload过载节点\nprobe_num=10\n\n;初始化host_info主机信息访问成功的个数，防止刚启动时少量失败就认为过载\ninit_succ_cnt=180\n\n;当idle节点切换至over_load时的初始化失败次数，主要为了累计一定成功次数才能切换会idle\ninit_err_cnt=5\n\n;当idle节点失败率高于此值，节点变overload状态\nerr_rate=0.1\n\n;当overload节点成功率高于此值，节点变成idle状态\nsucc_rate=0.5\n\n;当idle节点连续失败次数超过此值，节点变成overload状态\ncontin_err_limit=15\n\n;当overload节点连续成功次数超过此值, 节点变成idle状态\ncontin_succ_limit=15\n\n;整个窗口的真实失败率阈值\nwindow_err_rate=0.7\n\n;对于某个modid/cmdid下的某个idle状态的host，需要清理一次负载信息的周期\nidle_timeout=15\n\n;对于某个modid/cmdid/下的某个overload状态的host，在过载队列等待的最大时间\noverload_timeout=15\n\n;对于每个NEW状态的modid/cmdid，多久更新一下本地路由,秒\nupdate_timeout=15\n```\n\n## (4)启动\n**启动 lars reporter serivce**\n```bash\n    cd ./Lars\n    ./run_lars reporter\n```\n\n**启动 lars dns service**\n```bash\n    cd ./Lars\n    ./run_lars dns\n```\n\n**启动 lars lbagent service**\n```bash\n    cd ./Lars\n    ./run_lars lbagent\n```\n\n**启动 lars web service**\n```bash\n    cd ./Lars\n    ./run_lars web\n```\n\n## (5) Web管理端操作\n**打开浏览器,输入web 服务的ip地址+端口号**\n![lars_web_login.png](https://s2.ax1x.com/2019/11/29/QA8Zh4.png)\n\n**配置主机**\n![lars_web_add_host.png](https://s2.ax1x.com/2019/11/29/QAGoLt.png)\n\n**查看所有主机配置**\n![lars_web_all_hosts.png](https://s2.ax1x.com/2019/11/29/QAJvtO.png)\n\n## (6) 模拟效果测试\n**启动模拟器测试**\n```bash\n    cd ./Lars\n    ./run_lars test simulator 1 1\n```\n\n**更多测试工具**\n```bash\n    cd ./Lars\n    ./run_lars help\n```\n\n```bash\n\n=======启动子系统==========\nUsage ./run_lars [reporter|dns|lbagent|web|test]\n\n=======测试工具============\nUsage ./run_lars test gethost ModID CmdID\nUsage ./run_lars test getroute ModID CmdID\nUsage ./run_lars test report ModID CmdID IP Port 0|1  --- 0:SUCC, 1:OVERLOAD\nUsage ./run_lars test simulator ModID CmdID [errRate(0-10)] [queryCnt(0-999999)]\nUsage ./run_lars test qps ThreadNum\nUsage ./run_lars test example ModID CmdID\n\n```\n\n## (7)Web查看主机调用状态\n\n![lars_web_status.png](https://s2.ax1x.com/2019/11/29/QAteVx.png)\n\n# 五、Lars QPS性能测试\n**主机1**\n\u003e CPU个数：2个 ， 内存: 2GB ,   系统：Ubuntu18.04虚拟机\n\n| 线程数 | QPS    |\n| ------ | ------ |\n| 1      | 0.5w/s |\n| 2      | 2.2w/s |\n| 10     | 5.5w/s |\n| 100    | 5.3w/s |\n\n\n**主机2**\n\u003e CPU个数: 24个 , 内存:128GB， 系统: 云主机\n\n| 线程数    | QPS | \n| ------ | ------ |\n| 1 | 8.36w/s| \n| 3 | 28.06w/s| \n| 5 | 55.18w/s| \n| 8 | 56.74w/s| \n\n# Lars技术讨论社区\n\n---\n### About the author\n\n`name`：`Aceld(刘丹冰)`\n\n`mail`:\n[danbing.at@gmail.com](mailto:danbing.at@gmail.com)\n\n`github`:\n[https://github.com/aceld](https://github.com/aceld)\n\n`原创技术文章作品`:\n[https://www.yuque.com/aceld](https://www.yuque.com/aceld)\n\n### 技术讨论社区\n|  **WeChat**   | **WeChat Public Account**  | **QQ Group**  |\n|  ----  | ----  | ----  |\n| \u003cimg src=\"https://s1.ax1x.com/2020/07/07/UF6rNV.png\" width = \"150\" height = \"180\" alt=\"\" align=center /\u003e  | \u003cimg src=\"https://s1.ax1x.com/2020/07/07/UFyUdx.th.jpg\" height = \"150\"  alt=\"\" align=center /\u003e | \u003cimg src=\"https://s1.ax1x.com/2020/07/07/UF6Y9S.th.png\" width = \"150\" height = \"150\" alt=\"\" align=center /\u003e |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faceld%2Flars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faceld%2Flars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faceld%2Flars/lists"}