我可以在Nginx Conf中添加多少个服务器块 [英] How many server blocks can I add in Nginx Conf

查看:92
本文介绍了我可以在Nginx Conf中添加多少个服务器块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我可以在Nginx配置中添加多少个服务器块的任何想法? 我需要将其用于具有多个子域(每个客户端一个子域)的反向代理. 它可以成功支持10,000个服务器块吗? 是否有任何基准研究?

Any idea on how many server blocks I can add in Nginx configuration? I need to use it for reverse proxy with multiple subdomains (one subdomain for each client). Can it successfully support 10,000 server blocks? Are there any benchmark studies on it?

推荐答案

这实际上不是您可以拥有多少的问题,而是您有多少.可以体面地处理

This is not really a question of how many you can have but how many you.could handle decently

您可以有效处理的数量在很大程度上取决于您的硬件(不是为容器供电的硬件,而是实际运行nginx的框),因为Nginx大部分时间会尝试将哈希表放入Cache中(最好在L1上)缓存,因为它虽然较小,但速度较快,如果无法缓存,则为二级缓存) 那是基本理论.

How many you can handle efficiently will greatly depend on your hardware (not the hardware powering the containers but the actual box nginx is running on) as Nginx will most of the time try to fit the hash tables in Cache (preferably on L1 cache, as it is faster albeit small or, if unable, on L2 cache) That's the basic theory.

根据nginx文档,根据您的配置,每个服务器块将占用32/64/128字节的哈希,具体取决于您的配置,因此即使按1000个服务器块标记,您也可能不再位于L1上,这意味着您可能是从1-2纳秒的寻道时间移动到了10-15纳秒的寻道时间甚至更多(不记得确切的当前数字了...)继续增长,您甚至可能用完L2缓存(再次,这取决于您的实际硬件是什么),因此您现在使用L3缓存,甚至使用速度更慢的RAM.即使所有缓存都可以使命中率达到99%或更高,但是随着流量的增加,由于更多的CPU将专用于确定每个访问者的目的地,因此查找时间将成为一个问题.这只是假设所有服务器块都具有准确的域名,而不是通配符或正则表达式,而这会进一步影响性能.

According to nginx documentation, each server block would take 32/64/128 bytes for the hash depending on your configuration, so even by the 1000 server-block mark you're probably not on L1 any more, which means you're probably moving from 1-2 nanosecond seek times to maybe 10-15 nanosecond seek times or more (can't remember the exact current figures... These are ballpark). Keep growing and you might even run out of L2 cache (again, this will depend on what your actual hardware is) so you're now on L3 cache or even on RAM which is even slower. Even though all caches may render hit rates of 99% or better, seek times will become an issue as traffic grows as more CPU will be dedicated to just determining where each visitor intends to go. And this is just assuming that all server blocks have exact domain names and not wildcards or regex which would impact performance even further.

可以做到吗?当然...只要拥有一个坚固的CPU,就可以拥有最大的L1高速缓存,以及一个较大的L2高速缓存.如果您绝对必须这样做,请远离通配符和正则表达式 准备调整server_names_hash_max_sizeserver_names_hash_bucket_size配置指令(您将知道在添加服务器块之后需要执行此操作... Nginx可能花费异常/令人无法接受的时间来重新启动,或者根本不重新启动:这就是您的提示更改此处概述的那些指令:

Can it be done? Of course... Just get a sturdy CPU with the biggest L1 cache you can and a big L2 cache as well. And if you absolutely must do it, stay away from wildcards and regex Be ready to tune server_names_hash_max_size and server_names_hash_bucket_size config directives (you'll know you need to do it after adding the server blocks... Nginx may take unusually/unacceptably longer to restart or may not restart at all: that's your cue to changing those directives as outlined here:

http://nginx.org/en/docs/hash.html

在这里:

http://nginx.org/en/docs/http/ngx_http_core_module .html#server_names_hash_bucket_size

即使nginx确实重新启动,您也需要在流量开始增加时密切监视硬件,以确定瓶颈可能在多大程度上承受负载.最好的情况是,您将为每个请求添加一秒钟的时间...最坏的情况下,您可以将整个操作框放到膝盖以下(但这确实将其推到了极致)

Even if nginx does restart, you need to monitor your hardware closely as traffic starts ramping up in order to determine how serious your bottleneck may get under load. Best case scenario, you'll add a fraction of a second to each request... Worst case scenario you could bring the whole box down to it's knees (but that's really pushing it to the extreme)

说了这么多...您是否探索过其他选择?可能是通过DNS进行的,还是转向F5设备或其他一些较低级别的解决方案之类的企业级产品?

Having said all that... Have you explored other options? Doing it via DNS perhaps or moving to enterprise-grade stuff like an F5 device or some other lower-level solutions?

这篇关于我可以在Nginx Conf中添加多少个服务器块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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