Skip to content

Commit

Permalink
Implement limits for concurrent threads
Browse files Browse the repository at this point in the history
Add limits to the amount of Threads the Indexer and Patcher can run at the same time.

Co-Authored-By: Regalia <[email protected]>
  • Loading branch information
Nekromateion and regalialong committed Jun 25, 2024
1 parent 3814f9e commit c8ea08e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AdGoBye/Indexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void AddToIndex(string path)
public static void AddToIndex(IEnumerable<DirectoryInfo?> paths)
{
ConcurrentBag<Content> contents = [];
Parallel.ForEach(paths, path =>
Parallel.ForEach(paths, new ParallelOptions { MaxDegreeOfParallelism = Settings.Options.MaxIndexerThreads }, path =>
{
if (path != null && AddToIndexPart1(path.FullName, out var content) && content != null)
{
Expand Down
3 changes: 2 additions & 1 deletion AdGoBye/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
logger.Information("Loaded blocks for {blockCount} worlds and indexed {indexCount} pieces of content",
Blocklist.Blocks?.Count, db.Content.Count());

Parallel.ForEach(db.Content.Include(content => content.VersionMeta), content =>
Parallel.ForEach(db.Content.Include(content => content.VersionMeta),
new ParallelOptions { MaxDegreeOfParallelism = Settings.Options.MaxPatchThreads }, content =>
{
if (content.Type != ContentType.World) return;
Indexer.PatchContent(content);
Expand Down
2 changes: 2 additions & 0 deletions AdGoBye/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public class SettingsOptions
public bool DisablePluginInstallWarning { get; set; }
public bool DisableBackupFile { get; set; }
public bool EnableRecompression { get; set; }
public int MaxIndexerThreads { get; set; }
public int MaxPatchThreads { get; set; }
}
}
4 changes: 3 additions & 1 deletion AdGoBye/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"DisableBackupFile": false,
"BlocklistURLs": [],
"DisablePluginInstallWarning": false,
"EnableRecompression": false
"EnableRecompression": false,
"MaxIndexerThreads": 16,
"MaxPatchThreads": 16
},
"Logging": {
"LogLevel": {
Expand Down

0 comments on commit c8ea08e

Please sign in to comment.