summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2023-04-19 23:47:39 -0700
committerGarrett D'Amore <garrett@damore.org>2023-04-19 23:49:48 -0700
commit8bd3733fc234e9677068cfb4f2b50a35e4413eeb (patch)
treee9f6ed54b547df057ad0823c7448031cc5c712a2
parent547502d817127d7aa4b71500171403a93435a3e9 (diff)
downloadnng-8bd3733fc234e9677068cfb4f2b50a35e4413eeb.tar.gz
nng-8bd3733fc234e9677068cfb4f2b50a35e4413eeb.tar.bz2
nng-8bd3733fc234e9677068cfb4f2b50a35e4413eeb.zip
fixes #1619 Expose NNG_MAX_EXPIRE_THREADS via CMake
-rw-r--r--CMakeLists.txt12
-rw-r--r--src/core/aio.c15
2 files changed, 23 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef4c2bc8..eaf77c9a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+# Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
# Copyright (c) 2012 Martin Sustrik All rights reserved.
# Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
@@ -130,6 +130,16 @@ if (NNG_MAX_TASKQ_THREADS)
add_definitions(-DNNG_MAX_TASKQ_THREADS=${NNG_MAX_TASKQ_THREADS})
endif ()
+# Expire threads. This runs the timeout handling, and having more of them
+# reduces contention on the common locks used for aio expiration.
+# The default is to allocate up to max(8, ncpu). The upper limit can be
+# overridden here.
+set(NNG_MAX_EXPIRE_THREADS 8 CACHE STRING "Upper bound on expire threads, 0 for no limit")
+mark_as_advanced(NNG_MAX_EXPIRE_THREADS)
+if (NNG_MAX_EXPIRE_THREADS)
+ add_definitions(-DNNG_MAX_EXPIRE_THREADS=${NNG_MAX_EXPIRE_THREADS})
+endif()
+
# Platform checks.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
diff --git a/src/core/aio.c b/src/core/aio.c
index 771cbc95..2d288a40 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -1,5 +1,5 @@
//
-// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -796,14 +796,23 @@ nni_aio_sys_init(void)
int num_thr;
// We create a thread per CPU core for expiration by default.
-#ifndef NNG_EXPIRE_THREADS
num_thr = nni_plat_ncpu();
+#ifndef NNG_EXPIRE_THREADS
+#ifndef NNG_MAX_EXPIRE_THREADS
+#define NNG_MAX_EXPIRE_THREADS 8
+#endif
+ if ((num_thr > NNG_MAX_EXPIRE_THREADS) && (NNG_MAX_EXPIRE_THREADS > 0)) {
+ num_thr = NNG_MAX_EXPIRE_THREADS;
+ }
#else
num_thr = NNG_EXPIRE_THREADS;
#endif
- if (num_thr > 256) {
+ if (num_thr > 256) { // upper limits
num_thr = 256;
}
+ if (num_thr < 1) {
+ num_thr = 1;
+ }
nni_aio_expire_q_list =
nni_zalloc(sizeof(nni_aio_expire_q *) * num_thr);