mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
Added: The ability to set the number of threads (NOT SUPPORTED!) to use for tasks using THREAD_LIMIT environment variable.
This commit is contained in:
parent
b865103871
commit
587b49aaba
@ -17,7 +17,9 @@ public class CommandExecutor : IHandle<ApplicationStartedEvent>,
|
|||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
|
||||||
private static CancellationTokenSource _cancellationTokenSource;
|
private static CancellationTokenSource _cancellationTokenSource;
|
||||||
private const int THREAD_LIMIT = 3;
|
private const int THREAD_UPPER_BOUND = 10;
|
||||||
|
private const int THREAD_LOWER_BOUND = 2;
|
||||||
|
private const int THREAD_LIMIT = 2;
|
||||||
|
|
||||||
public CommandExecutor(IServiceFactory serviceFactory,
|
public CommandExecutor(IServiceFactory serviceFactory,
|
||||||
IManageCommandQueue commandQueueManager,
|
IManageCommandQueue commandQueueManager,
|
||||||
@ -117,7 +119,16 @@ public void Handle(ApplicationStartedEvent message)
|
|||||||
{
|
{
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
for (int i = 0; i < THREAD_LIMIT; i++)
|
var envLimit = Environment.GetEnvironmentVariable("THREAD_LIMIT") ?? $"{THREAD_LIMIT}";
|
||||||
|
int threadLimit = THREAD_LIMIT;
|
||||||
|
if (int.TryParse(envLimit, out int parsedLimit)) threadLimit = parsedLimit;
|
||||||
|
|
||||||
|
threadLimit = Math.Max(THREAD_LOWER_BOUND, threadLimit);
|
||||||
|
threadLimit = Math.Min(THREAD_UPPER_BOUND, threadLimit);
|
||||||
|
|
||||||
|
_logger.Info("Starting {} threads for tasks.", threadLimit);
|
||||||
|
|
||||||
|
for (int i = 0; i < threadLimit + 1; i++)
|
||||||
{
|
{
|
||||||
var thread = new Thread(ExecuteCommands);
|
var thread = new Thread(ExecuteCommands);
|
||||||
thread.Start();
|
thread.Start();
|
||||||
|
Loading…
Reference in New Issue
Block a user