Skip to content
Snippets Groups Projects
Commit c2c6ddc0 authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez
Browse files

decoder: limit number of threads


Using too many threads for decoding is not recommended and can
introduce latency.
Also during a call there are 2 live encoding and 2 live decoding,
so using all threads for every decoding is not useful and could
decrease performance and increase latency because of more
CPU context switch.
This is especially visible on machines with many logical cores
like AMD Threadrippers or some Intel CPUs.
Ideally, loads should use in total as many threads as logical cores
to profit from the full machine power while limiting context switches.

In this patch, decoders will use half the number of logical core,
with a maximum of 8 threads.

Change-Id: Ibe6c083c35fba972d930346629de2175625afd8c
Reviewed-by: default avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent e18892fb
Branches
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <unistd.h> #include <unistd.h>
#include <thread> // hardware_concurrency #include <thread> // hardware_concurrency
#include <chrono> #include <chrono>
#include <algorithm>
namespace ring { namespace ring {
...@@ -206,7 +207,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format) ...@@ -206,7 +207,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format)
} }
#endif #endif
decoderCtx_->thread_count = std::thread::hardware_concurrency(); decoderCtx_->thread_count = std::max(1u, std::min(8u, std::thread::hardware_concurrency()/2));
decoderCtx_->channels = format.nb_channels; decoderCtx_->channels = format.nb_channels;
decoderCtx_->sample_rate = format.sample_rate; decoderCtx_->sample_rate = format.sample_rate;
...@@ -299,7 +300,7 @@ int MediaDecoder::setupFromVideoData() ...@@ -299,7 +300,7 @@ int MediaDecoder::setupFromVideoData()
#endif #endif
RING_DBG("Decoding video using %s (%s)", inputDecoder_->long_name, inputDecoder_->name); RING_DBG("Decoding video using %s (%s)", inputDecoder_->long_name, inputDecoder_->name);
decoderCtx_->thread_count = std::thread::hardware_concurrency(); decoderCtx_->thread_count = std::max(1u, std::min(8u, std::thread::hardware_concurrency()/2));
#ifdef RING_ACCEL #ifdef RING_ACCEL
if (enableAccel_) { if (enableAccel_) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment