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. encode 与 decode

    decode 将其它编码的字符串转换成unicode编码,例如:str1.decode("gb2312"),表示将gb2312编码的字符串转换成unicode编码 encode 将 ...

  2. alpha-4

    前言 失心疯病源4 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 19:00~21:50 利用背景相减法完成背景构建与更新模块,查找关于blob更多的论文资 ...

  3. <Effective C++>读书摘要--Designs and Declarations<一>

    <Item 18> Make interfaces easy to use correctly and hard to use incorrectly 1.That being the c ...

  4. 3ds max启动慢怎么办?

      有时候启动3ds max的时候一直卡在启动界面进不去怎么办?   在百度上搜到了下面这个解决方案,试了下还真有用:   具体就是进到这个文件夹,然后分别进入第一个和第三个文件夹删掉autodesk ...

  5. html5 canvas 图像处理

    1.图像放大缩小 <script> var cvs = document.getElementById("canvas"); cvs.width = cvs.heigh ...

  6. RT-thread内核之系统时钟

    一.系统时钟 rt-thread的系统时钟模块采用全局变量rt_tick作为系统时钟节拍,该变量在系统时钟中断函数中不断加1.而系统时钟中断源和中断间隔一般由MCU硬件定时器(如stm32的嘀嗒定时器 ...

  7. 【bzoj2591】[Usaco 2012 Feb]Nearby Cows 树形dp

    题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into accoun ...

  8. 《转》玩转图片Base64编码

    引言 图片处理在前端工作中可谓占据了很重要的一壁江山.而图片的 base64 编码可能相对一些人而言比较陌生,本文不是从纯技术的角度去讨论图片的 base64 编码.标题略大,不过只是希望通过一些浅显 ...

  9. 转:浅谈Spectral Clustering 谱聚类

    浅谈Spectral Clustering Spectral Clustering,中文通常称为“谱聚类”.由于使用的矩阵的细微差别,谱聚类实际上可以说是一“类”算法. Spectral Cluste ...

  10. BZOJ2588:Count on a tree——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2588 Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你 ...