Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify bin/apisix to support the SO_REUSEPORT #1085

Merged
merged 7 commits into from
Feb 9, 2020
13 changes: 9 additions & 4 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ stream {

server {
{% for _, port in ipairs(stream_proxy.tcp or {}) do %}
listen {*port*};
listen {*port*} {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% for _, port in ipairs(stream_proxy.udp or {}) do %}
listen {*port*} udp;
listen {*port*} udp {% if enable_reuseport then %} reuseport {% end %};
{% end %}

preread_by_lua_block {
Expand Down Expand Up @@ -263,13 +263,13 @@ http {
server {
listen {* node_listen *};
{% if ssl.enable then %}
listen {* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %};
listen {* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
{% end %}

{% if enable_ipv6 then %}
listen [::]:{* node_listen *};
{% if ssl.enable then %}
listen [::]:{* node_ssl_listen *} ssl {% if ssl.enable_http2 then %} http2 {% end %};
listen [::]:{* node_ssl_listen *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% end %} {% -- if enable_ipv6 %}

Expand Down Expand Up @@ -507,6 +507,7 @@ local function init()
with_module_status = with_module_status,
node_ssl_listen = 9443, -- default value
error_log = {level = "warn"},
enable_reuseport = true, -- default true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value should be set in config.yaml, not here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

if not yaml_conf.apisix then
Expand All @@ -530,6 +531,10 @@ local function init()
sys_conf["worker_processes"] = "auto"
end

if sys_conf["enable_reuseport"] == false then
enable_reuseport = false
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use the enable_reuseport in config.yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

local conf_render = template.compile(ngx_tpl)
local ngxconf = conf_render(sys_conf)

Expand Down
1 change: 1 addition & 0 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apisix:
enable_admin_cors: true # Admin API support CORS response headers.
enable_debug: false
enable_dev_mode: false # Sets nginx worker_processes to 1 if set to true
enable_reuseport: true # Enable nginx SO_REUSEPORT switch if set to true.
enable_ipv6: true
config_center: etcd # etcd: use etcd to store the config value
# yaml: fetch the config value from local yaml file `/your_path/conf/apisix.yaml`
Expand Down