cpuworker: Off by one when calculating the onionskin processing room
In onion_queue.c
, our function have_room_for_onionskin()
uses the number of CPUs to calculate an average of time we processed an onionskin across all threads. For example:
/* How long would it take to process all the NTor cells in the queue? */
ntor_usec = estimated_usec_for_onionskins(
ol_entries[ONION_HANDSHAKE_TYPE_NTOR],
ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
The num_cpus
value is taken by calling get_num_cpus()
which returns the number of core the system has. However, our CPU worker thread pool is configured to always have an extra thread (see cpuworker.c
):
const int n_threads = get_num_cpus(get_options()) + 1;
And so we are off by one in terms of number of CPU for our calculation. Meaning that we are over estimating our ntor onionskin process time because our divisor is minus off by one from the real number of threads being used for onionskins.
This can lead to triggering the overload signal way too early on relays.
Edited by David Goulet