annotate src/os/unix/ngx_setaffinity.c @ 9299:2706b60dc225 default tip

Core: error logging rate limiting. With this change, error logging to files can be rate-limited with the "rate=" parameter. The parameter specifies allowed log messages rate to a particular file (per worker), in messages per second (m/s). By default, "rate=1000m/s" is used. Rate limiting is implemented using the "leaky bucket" method, similarly to the limit_req module. Maximum burst size is set to the number of log messages per second for each severity level, so "error" messages are logged even if the rate limit is hit by "info" messages (but not vice versa). When the limit is reached for a particular level, the "too many log messages, limiting" message is logged at this level. If debug logging is enabled, either for the particular log file or for the particular connection, rate limiting is not used.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 25 Jun 2024 22:58:56 +0300
parents 7296b38f6416
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2 /*
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
3 * Copyright (C) Nginx, Inc.
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
4 */
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
5
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
6
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
7 #include <ngx_config.h>
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
8 #include <ngx_core.h>
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
9
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
10
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11 #if (NGX_HAVE_CPUSET_SETAFFINITY)
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
12
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
13 void
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
14 ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log)
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15 {
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16 ngx_uint_t i;
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
17
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
18 for (i = 0; i < CPU_SETSIZE; i++) {
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
19 if (CPU_ISSET(i, cpu_affinity)) {
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
20 ngx_log_error(NGX_LOG_NOTICE, log, 0,
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
21 "cpuset_setaffinity(): using cpu #%ui", i);
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22 }
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
23 }
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25 if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
26 sizeof(cpuset_t), cpu_affinity) == -1)
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27 {
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
29 "cpuset_setaffinity() failed");
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
30 }
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 }
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33 #elif (NGX_HAVE_SCHED_SETAFFINITY)
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35 void
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
36 ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log)
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37 {
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
38 ngx_uint_t i;
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
39
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
40 for (i = 0; i < CPU_SETSIZE; i++) {
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
41 if (CPU_ISSET(i, cpu_affinity)) {
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
42 ngx_log_error(NGX_LOG_NOTICE, log, 0,
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
43 "sched_setaffinity(): using cpu #%ui", i);
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
44 }
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
45 }
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
46
6402
7296b38f6416 Core: added support for more than 64 CPUs in worker_cpu_affinity.
Vladimir Homutov <vl@nginx.com>
parents: 4549
diff changeset
47 if (sched_setaffinity(0, sizeof(cpu_set_t), cpu_affinity) == -1) {
4549
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49 "sched_setaffinity() failed");
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
50 }
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
51 }
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52
f31162fefe01 worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53 #endif