瀏覽代碼

Fix image encoding concurrency limit (#13532)

* Fix image encoding concurrency limit

The current FFmpeg image extractor is configured to use a resource pool size that always equals 2 times the number of CPU cores, which is somewhat excessive. Make the default equal to the core count instead of twice, and respect the `ParallelImageEncodingLimit` option.

* Fix code stype

* Check null value for unit tests
gnattu 5 月之前
父節點
當前提交
3f539472f3
共有 2 個文件被更改,包括 8 次插入2 次删除
  1. 7 1
      MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
  2. 1 1
      src/Jellyfin.Drawing/ImageProcessor.cs

+ 7 - 1
MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs

@@ -122,7 +122,13 @@ namespace MediaBrowser.MediaEncoding.Encoder
             _jsonSerializerOptions = new JsonSerializerOptions(JsonDefaults.Options);
             _jsonSerializerOptions = new JsonSerializerOptions(JsonDefaults.Options);
             _jsonSerializerOptions.Converters.Add(new JsonBoolStringConverter());
             _jsonSerializerOptions.Converters.Add(new JsonBoolStringConverter());
 
 
-            var semaphoreCount = 2 * Environment.ProcessorCount;
+            // Although the type is not nullable, this might still be null during unit tests
+            var semaphoreCount = serverConfig.Configuration?.ParallelImageEncodingLimit ?? 0;
+            if (semaphoreCount < 1)
+            {
+                semaphoreCount = Environment.ProcessorCount;
+            }
+
             _thumbnailResourcePool = new(semaphoreCount);
             _thumbnailResourcePool = new(semaphoreCount);
         }
         }
 
 

+ 1 - 1
src/Jellyfin.Drawing/ImageProcessor.cs

@@ -66,7 +66,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
         var semaphoreCount = config.Configuration.ParallelImageEncodingLimit;
         var semaphoreCount = config.Configuration.ParallelImageEncodingLimit;
         if (semaphoreCount < 1)
         if (semaphoreCount < 1)
         {
         {
-            semaphoreCount = 2 * Environment.ProcessorCount;
+            semaphoreCount = Environment.ProcessorCount;
         }
         }
 
 
         _parallelEncodingLimit = new(semaphoreCount);
         _parallelEncodingLimit = new(semaphoreCount);