[PATCH] The auto parameter of the worker_processes supports to detect the container environment.
Maxim Dounin
mdounin at mdounin.ru
Tue Apr 24 17:00:10 UTC 2018
Hello!
On Wed, Apr 25, 2018 at 12:47:13AM +0800, agile6v wrote:
> # HG changeset patch
> # User Agile6v <agile6v at agile6v.com>
> # Date 1524585905 -28800
> # Wed Apr 25 00:05:05 2018 +0800
> # Node ID 89793df28d1bcf2baf00e389e6806d32d7435886
> # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd
> The auto parameter of the worker_processes supports to detect the container environment.
>
>
> Docker mounts cgroup information into container starting with version 1.8,
> so it is possible to determine the appropriate number of CPUs based on the
> cgroup information in the container. Refer to JDK related implementation:
> https://bugs.openjdk.java.net/browse/JDK-8146115
>
>
> diff -r 7c614ef3c6ea -r 89793df28d1b auto/sources
> --- a/auto/sources Wed Apr 18 16:11:41 2018 +0300
> +++ b/auto/sources Wed Apr 25 00:05:05 2018 +0800
> @@ -192,8 +192,8 @@
> FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c
> FREEBSD_SENDFILE_SRCS=src/os/unix/ngx_freebsd_sendfile_chain.c
>
> -LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h"
> -LINUX_SRCS=src/os/unix/ngx_linux_init.c
> +LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h src/os/unix/ngx_container.h"
> +LINUX_SRCS="src/os/unix/ngx_linux_init.c src/os/unix/ngx_container.c"
> LINUX_SENDFILE_SRCS=src/os/unix/ngx_linux_sendfile_chain.c
>
>
> diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_container.c
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/src/os/unix/ngx_container.c Wed Apr 25 00:05:05 2018 +0800
> @@ -0,0 +1,418 @@
> +
> +/*
> + * Copyright (C) agile6v
> + * Copyright (C) Xiaomi, Inc.
> + */
> +
> +#include <ngx_config.h>
> +#include <ngx_core.h>
> +
> +#define NGX_BUFFER_SIZE 8192
> +#define PER_CPU_SHARES 1024
> +
> +typedef struct {
> + ngx_str_t root;
> + ngx_str_t path;
> + ngx_str_t mount_point;
> +} cgroup_subsystem_info;
> +
> +static cgroup_subsystem_info cpu_subsystem;
> +
> +static ngx_str_t proc_cgroup_file = ngx_string("/proc/self/cgroup");
> +static ngx_str_t proc_mount_file = ngx_string("/proc/self/mountinfo");
> +static ngx_str_t cpu_cfs_period = ngx_string("/cpu.cfs_period_us");
> +static ngx_str_t cpu_cfs_quota = ngx_string("/cpu.cfs_quota_us");
> +static ngx_str_t cpu_cfs_shares = ngx_string("/cpu.shares");
[...]
400+ lines of code to obtain a number which is expected to be
directly available via the sysconf(_SC_NPROCESSORS_ONLN) call
might be a bit too many.
Thank you for your effort, but no.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list