{"id":13847827,"url":"https://github.com/baidu/galaxy","last_synced_at":"2026-01-14T23:40:10.533Z","repository":{"id":25523489,"uuid":"28955570","full_name":"baidu/galaxy","owner":"baidu","description":"Galaxy is a cluster management system.","archived":true,"fork":false,"pushed_at":"2017-08-22T01:14:54.000Z","size":7601,"stargazers_count":326,"open_issues_count":18,"forks_count":111,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-05-20T09:56:53.034Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baidu.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-01-08T08:04:16.000Z","updated_at":"2025-01-14T19:12:38.000Z","dependencies_parsed_at":"2022-08-24T05:40:58.678Z","dependency_job_id":null,"html_url":"https://github.com/baidu/galaxy","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/baidu/galaxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fgalaxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fgalaxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fgalaxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fgalaxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baidu","download_url":"https://codeload.github.com/baidu/galaxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fgalaxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-08-04T19:00:32.852Z","updated_at":"2026-01-14T23:40:10.511Z","avatar_url":"https://github.com/baidu.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Galaxy\r\n[![Build Status](https://travis-ci.org/baidu/galaxy.svg?branch=master)](https://travis-ci.org/baidu/galaxy)  \r\nCopyright 2015, Baidu, Inc.  \r\nGalaxy是一个数据中心操作系统，目标是最大化资源的利用率与降低应用部署运维代价。\r\n\r\n#Galaxy 3.0设计\r\n\r\n# 背景\r\n\r\nGalaxy3.0是对Galaxy2.0的重构，主要解决以下问题：  \r\n\r\n1. 容器管理和服务管理紧耦合：服务的升级和启停都伴随容器的销毁和调度；\r\n2. 没有磁盘管理，只能管理home盘；\r\n3. 不支持用户quota和记账；\r\n4. 机器管理功能缺失；\r\n5. Naming功能可用性低；\r\n6. Trace功能不完善；\r\n\r\n# 系统架构\r\n\r\n        Galaxy3.0架构上分为2层： 资源管理层和服务管理层，每层都是主从式架构  \r\n        1. 资源管理层由ResMan(Resource Manager)和Agent构成  \r\n        2. 服务管理层由AppMaster和AppWorker构成;\r\n\r\n \r\n       +-------------------+-----------------------------+\r\n       |                   |               |             |\r\n       |                   |   MapReduce   |   Spark     |\r\n       |                   |               |             |\r\n       |                   +-----------------------------+\r\n       |                                                 |\r\n       |               Service Management                |  ---\u003e {AppMaster +　AppWorkers}\r\n       |                                                 |\r\n       +-------------------------------------------------+\r\n       |                                                 |\r\n       |               Resource Management               |  ---\u003e {ResMan + Agents}\r\n       |                                                 |\r\n       +-------------------------------------------------+\r\n\r\n## 1. 资源管理层（Resource Management)\r\n组件： ResMan + Agents  \r\n一个Galaxy集群只有一个处于工作状态的ResMan，负责容器的调度，为每个容器找到满足部署资源要求的机器；  \r\nResMan通过和部署在各个机器上的Agent通信，来创建和销毁容器；  \r\n容器： 一个基于linux cgroup和namspace技术的资源隔离环境；   \r\n容器里默认会启动AppWorker进程，是容器内的第一个进程，也就是根进程；   \r\nResMan不暴露给普通用户接口， 仅供内部组件以及集群管理员使用；  \r\n\r\n## 2. 服务管理层 (Service Management)\r\n组件：　AppMaster + AppWorkers  \r\nAppMaster是外界用户操作Galaxy的唯一入口；  \r\n一个Galaxy集群通常只有一个AppMaster，负责服务的部署、更新、启停和状态管理，把服务实例分发到各个机器上的容器内启动并跟踪状态；  \r\nAppMaster通过调用ResMan的RPC接口创建容器，容器内自动拉起AppWorker进程；  \r\n容器内的AppWorker进程通过和AppMaster进程通信，获得需要在容器内执行的命令，包括部署、启停、更新等等；  \r\nAppWorker会汇报服务的状态给AppMaster，例如托管的服务是否在正常运行，进程退出码等；  \r\n\r\n## 调度逻辑\r\n\r\n用户提交的Job内容主要是两部分：资源需求 +　程序描述  \r\n资源需求： CPU核数、内存大小、磁盘容量、机器Lable、端口范围、mount路径  \r\n程序描述： 部署命令、启动命令、停止命令、更新命令、版本号  \r\n\r\n### 1. ResMan的调度逻辑\r\nResMan通过定时查询Agent，获得每个Agent上面可分配的资源  \r\nResMan不断检查当前是否有处于Pending状态的容器， 寻找有资源的Agent创建容器；  \r\n创建失败的容器，又进入Pending状态，等待重新调度；  \r\n不符合预期的容器， ResMan命令Agent销毁， 重新进入Pending状态；  \r\nResMan确保容器的个数始终符合用户的需求；  \r\n\r\n### 2. AppMaster的调度逻辑\r\nAppMaster等待AppWorkers的定时汇报；  \r\n如果AppWorker汇报的服务状态不符合AppMaster的预期，则AppMaster返回一些命令让AppWorker执行；  \r\n\u003e a) 部署： AppWorker汇报目前没有运行任何服务， AppMaster返回部署命令给AppWorker;  \r\n\u003e b) 启动： AppWorker汇报部署成功了， AppMaster返回启动命令给AppWorker;  \r\n\u003e c) 更新： AppWorker汇报当前服务的版本号， AppMaster发现不匹配， 返回更新命令给AppWorker;  \r\n\u003e d) 失败处理： AppWorker汇报（部署失败 or 启动失败 or 更新失败）， AppMaster记录此次异常，并根据策略决定是否让AppWorker继续重试；  \r\n\r\n## 容错\r\n\r\n1. ResMan，AppMaster都有备份，通过Nexus抢锁来Standby;  \r\n2. Agent跟踪每个容器的状态汇报给ResMan，当容器个数不够或者不符合ResMan的要求时，就需要调度：创建或删除容器；  \r\n3. AppWorker负责跟踪用户程序的状态，当用户程序coredump、异常退出或者被cgroup kill后，反馈状态给AppMaster，AppMaster根据指定策略命令AppWorker是否再次拉起用户的服务； \r\n4. 由于机器缺陷或者网络分割，可能导致ResMan认为容器个数足够，但是AppMaster发现服务实例数不够的情况：  \r\n\u003e 例如： 磁盘坏了、端口被占用等， 导致用户服务始终无法拉起；  \r\n\u003e 这种情况下， AppMaster可以调用ResMan的接口，增大容器个数（有上限）；  \r\n\r\n## 服务发现\r\n1. SDK通过Nexus发现AppMaster地址；  \r\n2. SDK请求AppMaster，发现每个Job实例的地址和当前的服务状态；  \r\n3. AppMaster会定时同步服务地址和状态到第三方Naming系统（如BNS,Nexus,ZK等);  \r\n\r\n## 服务更新\r\n1. SDK通过Nexus发现指定的Job的AppMaster地址；  \r\n2. SDK请求AppMaster, AppMaster将服务更新命令传播给AppWorker, AppWorker将更新状态反馈给AppMaster;  \r\n3. AppWorker和AppMaster的通信方式是Pull的方式，因此AppMaster可以根据当前的情况来决定部署的暂停和步长控制；  \r\n4. 服务的更新都在容器内进行，不涉及到容器的销毁和创建  \r\n\r\n# 权限管理和quota管理模型\r\n1. 集群（Cluster）：共用同一ResMan的host/agent及服务\r\n2. 机器池（Pool）： 一个host/agent只能属于一个机器池，一个机器池通常有很多host/agent。一个集群中可能有多个机器池。机器池用于资源及环境的硬隔离， 也是权限分配的单位。\r\n3. 用户（User）：galaxy用户\r\n4. 权限（Authority）：某用户在某机器池上具有的某种操作权限，如对Job的增、删、改、查权限等。用户可以同时对多个机器池具有多项权限。\r\n5. 配额（Quota）：配额是对用户在集群中拥有资源量的描述， 包含cpu配额，内存配额， 磁盘空间配额，可提交任务数量配额等。用户的配额和具体的机器池没有关系。\r\n6. 标签（label）： 标签一般用来表征一批拥有某种特征的机器，标签和机器是多对多的关系。有权限的用户可以对机器池中的机器打标签，提交任务时可指定标签。\r\n\r\n# 系统依赖\r\n1. Nexus作为寻址和元信息保存  \r\n2. MDT作为用户日志的Trace系统  \r\n3. Sofa-PbRPC作为通信基础库  \r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fgalaxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaidu%2Fgalaxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fgalaxy/lists"}