nginx shared memory zone 共享内存区域

创建日期: 2024-04-29 15:05 | 作者: 风波 | 浏览次数: 21 | 分类: Nginx

来源:https://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone

Syntax: zone name [size]; Default: — Context: upstream This directive appeared in version 1.9.0.

Defines the name and size of the shared memory zone that keeps the group’s configuration and run-time state that are shared between worker processes. Several groups may share the same zone. In this case, it is enough to specify the size only once.

Additionally, as part of our commercial subscription, such groups allow changing the group membership or modifying the settings of a particular server without the need of restarting nginx. The configuration is accessible via the API module (1.13.3).

主要用来在多个 worker 之间同步状态信息。 如果 worker_processes 设置的数量大于1,那么默认情况下每个 worker 会使用自己的状态,这就导致轮询 Round Robin 机制部分失效。因为这个轮询的状态信息是每个 worker 私有的,所以当客户端请求量不够大的时候,这些请求基本都会被转发到第一个 backend 里面。

配置如下

upstream haha {
    zone haha_sm 10240m;
    server 172.17.0.1:81;
    server 172.17.0.1:82;
}

server {
    listen       80;
    server_name  _;  

    location /api {
        proxy_pass http://haha;
        proxy_connect_timeout   18000;
        proxy_send_timeout      18000;
        proxy_read_timeout      18000;
        client_max_body_size 10240m;
    }   
}
21 浏览
20 爬虫
0 评论