Skip to content

Commit

Permalink
fixes nanomsg#1202 More than 120 threads was started by NNG
Browse files Browse the repository at this point in the history
This introduces a new CMake option, NNG_MAX_TASKQ_THREADS, with
a default value of 16.  The number of taskq workers will generally
be calculated as vcpu * 2.  This new value, if not zero, sets an
upper bound.  Note that the value should be at least two, in order
to ensure no deadlocks occur.
  • Loading branch information
gdamore committed Feb 24, 2020
1 parent 4f7cf93 commit 15869e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ if (NNG_NUM_TASKQ_THREADS)
endif ()
mark_as_advanced(NNG_NUM_TASKQ_THREADS)

set(NNG_MAX_TASKQ_THREADS 16 CACHE STRING "Upper bound on taskq threads, 0 for no limit")
mark_as_advanced(NNG_MAX_TASKQ_THREADS)
if (NNG_MAX_TASKQ_THREADS)
add_definitions(-DNNG_MAX_TASKQ_THREADS=${NNG_MAX_TASKQ_THREADS})
endif ()

# Platform checks.

if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
Expand All @@ -152,7 +158,7 @@ endif ()
include(CheckAtomicLib)
CheckAtomicLib()
if (NOT HAVE_C_ATOMICS_WITHOUT_LIB AND HAVE_C_ATOMICS_WITH_LIB)
list(APPEND NNG_LIBS "atomic")
list(APPEND NNG_LIBS "atomic")
endif ()


Expand Down
5 changes: 5 additions & 0 deletions src/core/taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ nni_taskq_sys_init(void)
#else
nthrs = NNG_NUM_TASKQ_THREADS;
#endif
#if NNG_MAX_TASKQ_THREADS > 0
if (nthrs > NNG_MAX_TASKQ_THREADS) {
nthrs = NNG_MAX_TASKQ_THREADS;
}
#endif

return (nni_taskq_init(&nni_taskq_systq, nthrs));
}
Expand Down

0 comments on commit 15869e3

Please sign in to comment.