How GitLab uses Unicorn and unicorn-worker-killer
GitLab uses Unicorn, a pre-forking Ruby web server, to handle web requests (web browsers and Git HTTP clients). Unicorn is a daemon written in Ruby and C that can load and run a Ruby on Rails application; in our case the Rails application is GitLab Community Edition or GitLab Enterprise Edition.
Unicorn has a multi-process architecture to make better use of available CPU cores (processes can run on different cores) and to have stronger fault tolerance (most failures stay isolated in only one process and cannot take down GitLab entirely). On startup, the Unicorn 'master' process loads a clean Ruby environment with the GitLab application code, and then spawns 'workers' which inherit this clean initial environment. The 'master' never handles any requests, that is left to the workers. The operating system network stack queues incoming requests and distributes them among the workers.
In a perfect world, the master would spawn its pool of workers once, and then the workers handle incoming web requests one after another until the end of time. In reality, worker processes can crash or time out: if the master notices that a worker takes too long to handle a request it will terminate the worker process with SIGKILL ('kill -9'). No matter how the worker process ended, the master process will replace it with a new 'clean' process again. Unicorn is designed to be able to replace 'crashed' workers without dropping user requests.
This is what a Unicorn worker timeout looks like in unicorn_stderr.log. The master process has PID 56227 below.

翻译如下:
GitLab使用Unicorn,一个预先分配的Ruby Web服务器来处理Web请求(Web浏览器和Git HTTP客户端)。 Unicorn是一个用Ruby和C编写的守护进程,可以加载和运行Ruby on Rails应用程序;在我们的例子中,Rails应用程序是GitLab社区版或GitLab企业版。
Unicorn具有多进程架构,以更好地利用可用的CPU内核(进程可以在不同的内核上运行),并具有更强的容错能力(大多数故障只保留在一个进程中,并且不能完全取消GitLab)。在启动时,Unicorn的“主”进程使用GitLab应用程序代码加载一个干净的Ruby环境,然后生成继承这个干净的初始环境的“工作者”。 “主人”从不处理任何要求,留给工作人员。操作系统网络堆栈将进入的请求排队并将其分发给工作人员。
在一个完美的世界里,主人会产生一次工作池,然后工作人员一个接一个地处理传入的Web请求,直到时间结束。实际上,工作进程可能会崩溃或超时:如果主人注意到工作人员处理请求太长时间,则将使用SIGKILL('kill -9')终止工作进程。无论工作流程如何结束,主程序将重新替换新的“干净”流程。 Unicorn旨在能够替代“坠毁”的工作人员,而不会丢弃用户请求。
这是Unicorn工作超时在unicorn_stderr.log中看起来像什么。主程序下面有PID 56227
GitLab has memory leaks. These memory leaks manifest themselves in long-running processes, such as Unicorn workers. (The Unicorn master process is not known to leak memory, probably because it does not handle user requests.)
To make these memory leaks manageable, GitLab comes with the unicorn-worker-killer gem. This gem monkey-patches the Unicorn workers to do a memory self-check after every 16 requests. If the memory of the Unicorn worker exceeds a pre-set limit then the worker process exits. The Unicorn master then automatically replaces the worker process.
This is a robust way to handle memory leaks: Unicorn is designed to handle workers that 'crash' so no user requests will be dropped. The unicorn-worker-killer gem is designed to only terminate a worker process in between requests, so no user requests are affected.
This is what a Unicorn worker memory restart looks like in unicorn_stderr.log. You see that worker 4 (PID 125918) is inspecting itself and decides to exit. The threshold memory value was 254802235 bytes, about 250MB. With GitLab this threshold is a random value between 200 and 250 MB. The master process (PID 117565) then reaps the worker process and spawns a new 'worker 4' with PID 127549.
翻译如下:
GitLab有内存泄漏。这些内存泄漏在长时间运行的过程中显现,例如独角兽工人。 (独角兽主进程不知道会泄漏内存,可能是因为它不处理用户请求。)
为了使这些内存泄漏易于管理,GitLab带有独角兽工人杀手宝石。这个宝石猴子补丁独角兽工作人员在每16次请求后进行记忆自检。如果Unicorn工作人员的内存超过预设限制,则工作进程退出。独角兽主人会自动替换工作进程。
这是处理内存泄漏的强大方式:Unicorn旨在处理“崩溃”的工作人员,因此不会丢弃任何用户的请求。 unicorn-worker-killer gem被设计为仅在请求之间终止工作进程,因此不会影响用户请求。
这是一个Unicorn工作的内存重新启动看起来像unicorn_stderr.log。你看到工人4(PID 125918)正在检查自己并决定退出。阈值内存值为254802235字节,约为250MB。使用GitLab,该阈值是200到250 MB之间的随机值。主程序(PID 117565)然后收到工作进程,并使用PID 127549生成一个新的“工作人员4”。

How GitLab uses Unicorn and unicorn-worker-killer的更多相关文章
- Understanding Unicorn and unicorn-worker-killer Unicorn
We just wrote some new documentation on how Gitlab uses Unicorn and unicorn-worker-killer, available ...
- puppet master 用 nginx + unicorn 作为前端
目录 1. 概要 2. nginx + unicorn 配置 2.1. package 安装 2.2. 配置文件设置 2.2.1. 配置 unicorn 2.2.2. 配置nginx 2.3. 测试配 ...
- ror配置unicorn部署
unicorn是目前在ror上比较流行的应用服务器,配合nginx用来直接部署rails程序,下面这种方式应该是共享socket,不断fork子进程,有点类似php-fpm的模式 安装unicorn ...
- Setting up Unicorn with Nginx
gem install unicorn or gem 'unciron' 1 install Nginx yum install ... 2 Configuration vi /etc/nginx/n ...
- [7期]美少妇(msf)和独角兽(unicorn)
MSF 全称:metasploit-framework 渗透大杀器,黑客工具排名第一(靠前),尤其在内网中.在校期间大学生先跟本校安全部沟通好,一起实验. 得不到校方理解与认可的上SRC或者自己 ...
- gitlab服务器搭建教程
gitlab服务器搭建教程 ----2016年终总结 三 参考https://bbs.gitlab.cc/topic/35/gitlab-ce-8-7-%E6%BA%90%E7%A0%81%E5%AE ...
- Jenkins + Ansible + Gitlab之gitlab篇
前言 持续交付 版本控制器:Gitlab.GitHub 持续集成工具:jenkins 部署工具:ansible 课程安排 Gitlab搭建与流程使用 Ansible环境配置与Playbook编写规范 ...
- 【Git】 GitLab配置优化及汉化
GitLab配置 1.修改GitLab绑定的域名 a.修改/etc/gitlab/gitlab.rb配置文件,修改成自己的域名 external_url 'http://gitlab.example. ...
- 二、CentOS 7安装部署GitLab服务器(解决邮箱发信问题)
一.环境安装(10.0.0) 1.安装依赖软件 yum -y install policycoreutils policycoreutils-python openssh-server openssh ...
- GitLab 架构
GitLab 架构官方文档 GitLab 中文文档 版本 一般使用的是社区版(Community Edition,CE),此外还有企业版(Enterprise Edition,EE)可以使用. EE ...
随机推荐
- Python中如何Getting Help
在Python中Gettting Help有如下两种方法: 1 使用dir函数,dir的参数可以是一个真正的对象实例,也可以是一个数据类型,无论哪种情形,dir函数都返回与这个对象或者数据类型相关联的 ...
- Catch That Cow(BFS广搜)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- 学霸系统PipeLine功能规格说明书
学霸系统PipeLine功能规格说明书共分为以下三部分: 1.产品面向用户群体 2.用户使用说明 3.产品功能具体实现 1.产品面向用户群体 我们这组的项目并不是传统意义上能发布并进行展示的项目,因此 ...
- python执行linux命令的两种方法
python执行linux命令有两种方法: 在此以Linux常用的ls命令为例: 方法一:使用os模块 1 2 3 shell# python >> import os >> ...
- Java容器之List接口
List 接口: 1. List 接口是 Collection 的子接口,实现 List 接口的容器类中的元素是有顺序的,而且可以重复: 2. List 容器中的元素都对应一个整数型的序号记载其在容器 ...
- lintcode-148-颜色分类
148-颜色分类 给定一个包含红,白,蓝且长度为 n 的数组,将数组元素进行分类使相同颜色的元素相邻,并按照红.白.蓝的顺序进行排序. 我们可以使用整数 0,1 和 2 分别代表红,白,蓝. 注意事项 ...
- LintCode-70.二叉树的层次遍历 II
二叉树的层次遍历 II 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 按照 ...
- pfx 证书怎么打开
其实双击就能够自动运行导入向导的 不行的话使用我的办法: 单击开始--运行--里输入mmc 然后单击文件--选择添加删除管理单元--再选择添加--拉动滚动条找到证书一项,点击添加再点击完成(不用做任何 ...
- Ansys Workbench热流固耦合仿真配置
1.Fluent-Thermal-Structural瞬态分析 此模块连接在fluent已实现流体和固体的热流耦合,传递至thermal实际上只是将流体表面温度作为热载荷施加在固体的液体通道表面,极大 ...
- input 元素 相对父元素错位
<div class="recommend"> <i class="iconfont icon-user"></i> < ...