是否有必要将Unicorn放在Nginx(或Apache)的后面 [英] Is it necessary to put Unicorn behind Nginx ( or Apache)

查看:86
本文介绍了是否有必要将Unicorn放在Nginx(或Apache)的后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这种体系结构有些困惑.在我正在从事的项目之一中,Unicorn被选作Rails服务器.它被放置在Nginx Web服务器之后.据我了解,Unicorn是功能齐全的Web服务器,我们不打算在同一服务器实例上托管任何其他Rails应用程序.

所以我的问题是:在链中增加额外的层有什么好处:

client -> nginx -> unicorn -> unicorn worker

解决方案

Unicorn并非旨在处理慢客户端".您可以在 PHILOSOPHY 帮助文件中了解有关此内容的更多信息:

我们见过的大多数基准测试都无法告诉您这一点,而独角兽公司并不在乎缓慢的客户...但是您应该这样做.

慢客户端"可以是数据中心之外的任何客户端.本地网络中的网络流量始终比经过其外部的流量要快.物理定律不允许这样做.

HTTP/1.1中引入了持久连接,减少了建立连接和TCP缓慢启动的延迟.当客户端闲置时,它们还会浪费服务器资源.

持久连接意味着独角兽工作进程之一(取决于您的应用程序,它可能非常消耗内存)将花费大量时间空闲以保持连接活动并且不执行任何其他操作.由于是单线程并使用阻塞的I/O,工作线程无法在保持连接活动的同时为其他客户端提供服务.因此,独角兽无法实现持久连接.

如果您的应用程序响应大于套接字缓冲区,或者您正在处理较大的请求(上载),则工作进程也会因客户端连接的速度而成为瓶颈.您不应该允许独角兽为您的本地网络以外的客户提供服务.

I'm a bit confused about this architecture. On one of the projects I'm working on, Unicorn was chosen as a Rails server. And it is put behind Nginx web server. As I understand Unicorn is fully functional web server and we don't plan to host any other Rails applications on the same server instance.

So my question would be: what are the benefits of having additional layer in chain:

client -> nginx -> unicorn -> unicorn worker

解决方案

Unicorn was not designed to handle "slow clients". You can read more about this in the PHILOSOPHY help file:

Most benchmarks we’ve seen don’t tell you this, and unicorn doesn’t care about slow clients… but you should.

A "slow client" can be any client outside of your datacenter. Network traffic within a local network is always faster than traffic that crosses outside of it. The laws of physics do not allow otherwise.

Persistent connections were introduced in HTTP/1.1 reduce latency from connection establishment and TCP slow start. They also waste server resources when clients are idle.

Persistent connections mean one of the unicorn worker processes (depending on your application, it can be very memory hungry) would spend a significant amount of its time idle keeping the connection alive and not doing anything else. Being single-threaded and using blocking I/O, a worker cannot serve other clients while keeping a connection alive. Thus unicorn does not implement persistent connections.

If your application responses are larger than the socket buffer or if you’re handling large requests (uploads), worker processes will also be bottlenecked by the speed of the client connection. You should not allow unicorn to serve clients outside of your local network.

这篇关于是否有必要将Unicorn放在Nginx(或Apache)的后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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