Heroku 上的瘦与独角兽 [英] Thin vs Unicorn on Heroku

查看:40
本文介绍了Heroku 上的瘦与独角兽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想了解人们对使用 Unicorn vs Thin 作为 Rails 服务器的看法.我在网上找到的大多数文章/基准似乎都很不完整,所以最好有一个集中的地方来讨论它.

Just wanted to get people's opinions on using Unicorn vs Thin as a rails server. Most of the articles/benchmarks I found online seem very incomplete, so it would nice to have a centralized place to discuss it.

Unicron 是一个多进程服务器,而 Thin 是一个基于事件/非阻塞的服务器.基于事件的服务器很棒……如果您的代码是异步/非阻塞的 - vanilla rails 正在阻塞.所以除非你使用非阻塞 rails 库,否则我真的看不到使用 Thin 的优势.更糟糕的是,在非阻塞服务器中,如果您的 i/o 循环被阻塞,您将阻塞整个循环并且在阻塞调用返回之前无法处理更多请求.阻塞的库会变慢!

Unicron is a multi-processes server, while thin is an event based/non-blocking server. Event-based servers are great... if your code is asynchronous/non-blocking - vanilla rails is blocking. So unless you use non-blocking rails libraries, I really don't see the advantage of using Thin. Even worse, in a non-blocking server, if your i/o loop is blocking you're going to block the entire loop and not be able to handle any more requests until the blocking call returns. Blocking libraries are going to slow thin down!

为什么 Heroku 选择 Thin 作为他们的默认服务器(用于 cedar)?他们是聪明人,所以我相信他们是有理由的.

Why did Heroku choose Thin as their default server (for cedar)? They are smart guys, so I'm sure they had a reason.

Bellow 是一个链接,建议用 4 个 Unicorn 工人替换 Thin - 这对我来说非常有意义.Heroku 上的 4 名 Unicron 工作人员

Bellow is a link that suggests replacing Thin with 4 Unicorn workers - this makes perfect sense to me. 4 Unicron workers on Heroku

推荐答案

Thin 易于配置 - 不是最优的,但它只适用于 Heroku 环境.

Thin is easy to configure - not optimal, but it just works in the Heroku environment.

Unicorn 可以更高效,但需要配置:多少工人?预加载应用程序?你选什么?

Unicorn can be more efficient, but it needs to be configured: How many workers? Preload App? What do you pick?

我发布了 Unicorn Heroku 应用程序,工作人员设置为 3、5 和 8 - 仅基于每个应用程序的大小 - 代码量、使用的内存量以及您获得的流量都用于选择这个数字,并且您需要随着时间的推移进行监控以确保您的号码正确,并且您的应用不会耗尽内存.

I have released Unicorn Heroku apps with workers set to 3, 5 and 8 - just based on how big each app is - how much code, how much memory is used and how much traffic you get all go into picking this number, and you need to monitor over time to make sure you got the number right, and your app isn't running out of memory.

Preload false - 这会使您的应用程序启动速度变慢,但是当 Unicorn 重新启动工作程序时,这对于网络连接(memcache、postgres、mongo 等)来说更安全"

Preload false - this will make your app start slower, but when Unicorn restarts a worker, this is 'safer' with network connections (memcache, postgres, mongo etc)

Preload true - 这更好,但您需要在分叉前和分叉后代码中正确处理服务器重新连接.

Preload true - this is better, but you need to handle server re-connections correctly in the pre and post fork code.

Thin 没有开箱即用的这些问题,但您只能获得执行过程.

Thin has none of these issues out of the box, but you only get process of execution.

总结:开箱即用地配置 Unicorn 以使其适合所有人(或根本无法正常工作)真的很难,而 Thin 可以让人们以较少的支持请求运行.

Summary: It's really hard to configure Unicorn out of the box to work well (or at all) for everyone, whereas Thin can just work to get people running with fewer support requests.

这篇关于Heroku 上的瘦与独角兽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆