chttpclient · Section 3
chttpcli_set_engine_num_reactor_threads
NAME
chttpcli_set_engine_num_reactor_threads - set the OS thread count of the async engine reactor of chttpclient
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpclient.h> ccol_retval chttpcli_set_engine_num_reactor_threads(size_t num_threads);
DESCRIPTION
This function sets how many OS threads the async engine's shared ceventloop reactor (the one behind Tier 2 and Tier 3) uses for polling and dispatch. The rules of the num_reactor_threads parameter of ceventloop_create_mp apply (see cthreadcomm.h): 1 means a single thread that both polls and dispatches inline, and a larger value means one dedicated poller thread plus (num_threads - 1) dispatch worker threads. By default the reactor sizes itself to sysconf(_SC_NPROCESSORS_ONLN), or to 1 if that query fails. You get this default when you never call the function, and also when you call it with num_threads == 0. A positive num_threads replaces the automatic size and pins the reactor to exactly that many threads, and a num_threads of 0 brings the automatic size back. The setting only affects how the shared reactor is built and has nothing to do with the settings of any single chttpcli instance. You can call this function at only two points: Before the reactor first starts in this process (before the first call to chttpcli_do_async or chttpcli_do_async_streaming anywhere), or after the engine has stopped completely. The engine stops once every async user of a chttpcli has dropped its reference and the automatic teardown has finished, and chttpcli_engine_wait blocks until that teardown is over. The reactor behind chttpsvr_set_engine_num_reactor_threads usually lives as long as the process, but this engine starts and stops along with the Tier 2 and Tier 3 traffic, so the window for this call opens again every time the engine stops and is not a one-time chance at process start.
RETURN VALUE
ccol_success, if the call succeeds.
ccol_not_permitted, while the engine runs. Wait for the engine to stop
completely first.
SEE ALSO
chttpcli_engine_wait(3), chttpcli_set_engine_mem_mgmt_procs(3), chttpcli_set_engine_logger(3), chttpcli_do_async(3), chttpcli_do_pooled(3), chttpsvr_set_engine_num_reactor_threads(3)