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的更多相关文章

  1. Understanding Unicorn and unicorn-worker-killer Unicorn

    We just wrote some new documentation on how Gitlab uses Unicorn and unicorn-worker-killer, available ...

  2. puppet master 用 nginx + unicorn 作为前端

    目录 1. 概要 2. nginx + unicorn 配置 2.1. package 安装 2.2. 配置文件设置 2.2.1. 配置 unicorn 2.2.2. 配置nginx 2.3. 测试配 ...

  3. ror配置unicorn部署

    unicorn是目前在ror上比较流行的应用服务器,配合nginx用来直接部署rails程序,下面这种方式应该是共享socket,不断fork子进程,有点类似php-fpm的模式 安装unicorn ...

  4. Setting up Unicorn with Nginx

    gem install unicorn or gem 'unciron' 1 install Nginx yum install ... 2 Configuration vi /etc/nginx/n ...

  5. [7期]美少妇(msf)和独角兽(unicorn)

    MSF 全称:metasploit-framework    渗透大杀器,黑客工具排名第一(靠前),尤其在内网中.在校期间大学生先跟本校安全部沟通好,一起实验. 得不到校方理解与认可的上SRC或者自己 ...

  6. gitlab服务器搭建教程

    gitlab服务器搭建教程 ----2016年终总结 三 参考https://bbs.gitlab.cc/topic/35/gitlab-ce-8-7-%E6%BA%90%E7%A0%81%E5%AE ...

  7. Jenkins + Ansible + Gitlab之gitlab篇

    前言 持续交付 版本控制器:Gitlab.GitHub 持续集成工具:jenkins 部署工具:ansible  课程安排 Gitlab搭建与流程使用 Ansible环境配置与Playbook编写规范 ...

  8. 【Git】 GitLab配置优化及汉化

    GitLab配置 1.修改GitLab绑定的域名 a.修改/etc/gitlab/gitlab.rb配置文件,修改成自己的域名 external_url 'http://gitlab.example. ...

  9. 二、CentOS 7安装部署GitLab服务器(解决邮箱发信问题)

    一.环境安装(10.0.0) 1.安装依赖软件 yum -y install policycoreutils policycoreutils-python openssh-server openssh ...

  10. GitLab 架构

    GitLab 架构官方文档 GitLab 中文文档 版本 一般使用的是社区版(Community Edition,CE),此外还有企业版(Enterprise Edition,EE)可以使用. EE ...

随机推荐

  1. 20170413B端业务访问故障排查思路

    现象: 1.全国用户电视端页面无法显示,刷不出版面. 2.后端服务无法打开,报错,504,502   显示服务器端业务故障超时. 3.其他业务也出现缓慢情况,并不严重. 排查: 1.系统服务排查,常规 ...

  2. Alpha发布——视频展示

    一.视频链接 http://v.youku.com/v_show/id_XMzEyODQzNzQ2MA==.html 二.视频文案说明 你是不是还在为软工作业奋笔疾书? 你是不是无法及时查看最新博客信 ...

  3. 开启假期JAVA之路

    . 从最基础的JAVA开始学起,已经上了三节课啦!希望在课程结束后能完成一个令自己满意的连连看项目,期待ing~ 慢慢的从简单的代码上手了~ . 用循环输出等腰三角形的效果 import java.u ...

  4. 用 C# 实现文件信息统计(wc)命令行程序

    软件的需求分析 程序处理用户需求的模式为: wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数与程序交互,需实现的功能如下: 1.基本功能 支持 - ...

  5. Swift-assert使用时机

    什么时候使用断言呢? 包含下面的情况时使用断言: 1.整型下标索引作为值传给自定义索引实现的参数时,但下标索引值不能太低也不能太高时,使用断言 2.传值给函数但如果这个传过来的值无效时,函数就不能完成 ...

  6. lol人物模型提取(八)

      今天顺风终于把包裹送到了北航新主楼自提柜,怀着激动喜悦的心情,我小心翼翼地将其取回.   到了晚上,是时候解开佐伊的封印了!   开了个小口,发现里面包得还挺严实的.   去掉了纸盒,里面还有一层 ...

  7. tweenjs缓动算法使用小实例

    这里的tweenjs不是依托于createjs的tewwnjs,而是一系列缓动算法集合.因为本身是算法,可以用在各个业务场景中,这也正是总结学习它的价值所在.tweenjs代码详情: /* * Twe ...

  8. 数字证书认证这点事, SSL/TLS,OpenSSL

    1.概念 数字证书 HTTPS请求时,Server发给浏览器的认证数据,用私钥签名,并且告诉浏览器公钥,利用公钥解密签名,确认Server身份. 证书还会指明相应的CA,CA能确认证书是否真的是CA颁 ...

  9. [C/C++] 字符串错题集

    1. 答案:A 这里考查转义字符,注意 \\ 表示字符 \\123表示字符 {\t 表示制表符这些都是一个字符. 2. 答案C 先不看有没有重复的,共5个字母,有5×4×3×2×1 = 120种组合. ...

  10. [C/C++] C++模板定义格式

    函数模板的格式: template <class 形参名,class 形参名,......> 返回类型 函数名(参数列表) { //函数体 } 类模板的格式为: template<c ...