From bd172571e7b1c37ee761e7c626901172b1fb6c2e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 4 Jun 2024 03:09:29 +0100 Subject: [PATCH 1/3] Prewarmer limit contended path to physical cores not logical cores --- .../Processing/BlockCachePreWarmer.cs | 3 ++- .../Cpu/ConsoleExitHandler.cs | 2 +- .../{Nethermind.Init => Nethermind.Core}/Cpu/CpuInfo.cs | 4 ++-- .../Cpu/DefaultCultureInfo.cs | 2 +- .../{Nethermind.Init => Nethermind.Core}/Cpu/Frequency.cs | 4 ++-- .../Cpu/FrequencyUnit.cs | 4 ++-- .../Cpu/ProcCpuInfoKeyNames.cs | 2 +- .../Cpu/ProcCpuInfoParser.cs | 2 +- .../Cpu/ProcCpuInfoProvider.cs | 2 +- .../Cpu/ProcessExtensions.cs | 2 +- .../Cpu/ProcessHelper.cs | 2 +- .../Cpu/RuntimeInformation.cs | 8 +++++--- .../Cpu/SectionsHelper.cs | 2 +- .../Cpu/SysctlCpuInfoParser.cs | 2 +- .../Cpu/SysctlCpuInfoProvider.cs | 2 +- .../Cpu/TimeInterval.cs | 4 ++-- .../{Nethermind.Init => Nethermind.Core}/Cpu/TimeUnit.cs | 4 ++-- .../Cpu/UnitPresentation.cs | 4 ++-- .../Cpu/WmicCpuInfoKeyNames.cs | 2 +- .../Cpu/WmicCpuInfoParser.cs | 2 +- .../Cpu/WmicCpuInfoProvider.cs | 2 +- src/Nethermind/Nethermind.Init/Steps/LogHardwareInfo.cs | 3 ++- 22 files changed, 34 insertions(+), 30 deletions(-) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ConsoleExitHandler.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/CpuInfo.cs (95%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/DefaultCultureInfo.cs (94%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/Frequency.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/FrequencyUnit.cs (94%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ProcCpuInfoKeyNames.cs (94%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ProcCpuInfoParser.cs (99%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ProcCpuInfoProvider.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ProcessExtensions.cs (99%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/ProcessHelper.cs (97%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/RuntimeInformation.cs (81%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/SectionsHelper.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/SysctlCpuInfoParser.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/SysctlCpuInfoProvider.cs (95%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/TimeInterval.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/TimeUnit.cs (97%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/UnitPresentation.cs (93%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/WmicCpuInfoKeyNames.cs (93%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/WmicCpuInfoParser.cs (98%) rename src/Nethermind/{Nethermind.Init => Nethermind.Core}/Cpu/WmicCpuInfoProvider.cs (96%) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs index 76ef5770efb..00a77049f85 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockCachePreWarmer.cs @@ -9,6 +9,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Specs; using Nethermind.Core.Threading; +using Nethermind.Core.Cpu; using Nethermind.Evm; using Nethermind.Evm.Tracing; using Nethermind.Evm.TransactionProcessing; @@ -54,7 +55,7 @@ private void PreWarmCachesParallel(Block suggestedBlock, Hash256 parentStateRoot try { - ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 2), CancellationToken = cancellationToken }; + ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = Math.Max(1, RuntimeInformation.PhysicalCoreCount - 2), CancellationToken = cancellationToken }; IReleaseSpec spec = specProvider.GetSpec(suggestedBlock.Header); WarmupTransactions(parallelOptions, spec, suggestedBlock, parentStateRoot); diff --git a/src/Nethermind/Nethermind.Init/Cpu/ConsoleExitHandler.cs b/src/Nethermind/Nethermind.Core/Cpu/ConsoleExitHandler.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/ConsoleExitHandler.cs rename to src/Nethermind/Nethermind.Core/Cpu/ConsoleExitHandler.cs index 53f6c8d2890..5b5dabc4d07 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ConsoleExitHandler.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ConsoleExitHandler.cs @@ -7,7 +7,7 @@ using System; using System.Diagnostics; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal class ConsoleExitHandler : IDisposable { diff --git a/src/Nethermind/Nethermind.Init/Cpu/CpuInfo.cs b/src/Nethermind/Nethermind.Core/Cpu/CpuInfo.cs similarity index 95% rename from src/Nethermind/Nethermind.Init/Cpu/CpuInfo.cs rename to src/Nethermind/Nethermind.Core/Cpu/CpuInfo.cs index 8e374810f34..a0c3eaadb48 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/CpuInfo.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/CpuInfo.cs @@ -4,9 +4,9 @@ // Derived from https://github.com/dotnet/BenchmarkDotNet // Licensed under the MIT License -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal class CpuInfo +public class CpuInfo { public string ProcessorName { get; } public int? PhysicalProcessorCount { get; } diff --git a/src/Nethermind/Nethermind.Init/Cpu/DefaultCultureInfo.cs b/src/Nethermind/Nethermind.Core/Cpu/DefaultCultureInfo.cs similarity index 94% rename from src/Nethermind/Nethermind.Init/Cpu/DefaultCultureInfo.cs rename to src/Nethermind/Nethermind.Core/Cpu/DefaultCultureInfo.cs index 060243b5849..23465e1ceac 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/DefaultCultureInfo.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/DefaultCultureInfo.cs @@ -6,7 +6,7 @@ using System.Globalization; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class DefaultCultureInfo { diff --git a/src/Nethermind/Nethermind.Init/Cpu/Frequency.cs b/src/Nethermind/Nethermind.Core/Cpu/Frequency.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/Frequency.cs rename to src/Nethermind/Nethermind.Core/Cpu/Frequency.cs index 32e2a60a958..e2c8328b83f 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/Frequency.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/Frequency.cs @@ -6,9 +6,9 @@ using System.Globalization; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal readonly struct Frequency +public readonly struct Frequency { public static readonly Frequency Zero = new Frequency(0.0); diff --git a/src/Nethermind/Nethermind.Init/Cpu/FrequencyUnit.cs b/src/Nethermind/Nethermind.Core/Cpu/FrequencyUnit.cs similarity index 94% rename from src/Nethermind/Nethermind.Init/Cpu/FrequencyUnit.cs rename to src/Nethermind/Nethermind.Core/Cpu/FrequencyUnit.cs index 9239c1e55cb..2b0de6bce90 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/FrequencyUnit.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/FrequencyUnit.cs @@ -4,9 +4,9 @@ // Derived from https://github.com/AndreyAkinshin/perfolizer // Licensed under the MIT License -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal class FrequencyUnit +public class FrequencyUnit { public static readonly FrequencyUnit Hz = new FrequencyUnit("Hz", "Hertz", 1L); diff --git a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoKeyNames.cs b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoKeyNames.cs similarity index 94% rename from src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoKeyNames.cs rename to src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoKeyNames.cs index 8f2555a629b..49960868ff5 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoKeyNames.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoKeyNames.cs @@ -4,7 +4,7 @@ // Derived from https://github.com/dotnet/BenchmarkDotNet // Licensed under the MIT License -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class ProcCpuInfoKeyNames { diff --git a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoParser.cs b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoParser.cs similarity index 99% rename from src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoParser.cs rename to src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoParser.cs index 8db1a4c52f4..f27aa681861 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoParser.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoParser.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Text.RegularExpressions; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static partial class ProcCpuInfoParser { diff --git a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoProvider.cs b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoProvider.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoProvider.cs rename to src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoProvider.cs index 5fc0d320b4e..c2d6fd770a7 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ProcCpuInfoProvider.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ProcCpuInfoProvider.cs @@ -7,7 +7,7 @@ using System; using System.Linq; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; /// /// CPU information from output of the `cat /proc/info` command. diff --git a/src/Nethermind/Nethermind.Init/Cpu/ProcessExtensions.cs b/src/Nethermind/Nethermind.Core/Cpu/ProcessExtensions.cs similarity index 99% rename from src/Nethermind/Nethermind.Init/Cpu/ProcessExtensions.cs rename to src/Nethermind/Nethermind.Core/Cpu/ProcessExtensions.cs index de38f80de2c..d725868961b 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ProcessExtensions.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ProcessExtensions.cs @@ -10,7 +10,7 @@ using System.Diagnostics; using System.IO; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; // we need it public to reuse it in the auto-generated dll // but we hide it from intellisense with following attribute diff --git a/src/Nethermind/Nethermind.Init/Cpu/ProcessHelper.cs b/src/Nethermind/Nethermind.Core/Cpu/ProcessHelper.cs similarity index 97% rename from src/Nethermind/Nethermind.Init/Cpu/ProcessHelper.cs rename to src/Nethermind/Nethermind.Core/Cpu/ProcessHelper.cs index 1c3bf460459..a4a3291e3f9 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/ProcessHelper.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/ProcessHelper.cs @@ -7,7 +7,7 @@ using System; using System.Diagnostics; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class ProcessHelper { diff --git a/src/Nethermind/Nethermind.Init/Cpu/RuntimeInformation.cs b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs similarity index 81% rename from src/Nethermind/Nethermind.Init/Cpu/RuntimeInformation.cs rename to src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs index 4dbbacf6869..e0c23df2cd3 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/RuntimeInformation.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs @@ -6,9 +6,9 @@ using System; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal static class RuntimeInformation +public static class RuntimeInformation { [System.Runtime.Versioning.SupportedOSPlatformGuard("windows")] internal static bool IsWindows() => OperatingSystem.IsWindows(); // prefer linker-friendly OperatingSystem APIs @@ -19,7 +19,7 @@ internal static class RuntimeInformation [System.Runtime.Versioning.SupportedOSPlatformGuard("macos")] internal static bool IsMacOS() => OperatingSystem.IsMacOS(); - internal static CpuInfo? GetCpuInfo() + public static CpuInfo? GetCpuInfo() { if (IsWindows()) return WmicCpuInfoProvider.WmicCpuInfo.Value; @@ -31,5 +31,7 @@ internal static class RuntimeInformation return null; } + public static int PhysicalCoreCount { get; } = GetCpuInfo()?.PhysicalCoreCount ?? Environment.ProcessorCount; + public static bool Is64BitPlatform() => IntPtr.Size == 8; } diff --git a/src/Nethermind/Nethermind.Init/Cpu/SectionsHelper.cs b/src/Nethermind/Nethermind.Core/Cpu/SectionsHelper.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/SectionsHelper.cs rename to src/Nethermind/Nethermind.Core/Cpu/SectionsHelper.cs index f65f1a432c2..34e3cec0847 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/SectionsHelper.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/SectionsHelper.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text.RegularExpressions; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static partial class SectionsHelper { diff --git a/src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoParser.cs b/src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoParser.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoParser.cs rename to src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoParser.cs index af67becb1fb..08071d70553 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoParser.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoParser.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class SysctlCpuInfoParser { diff --git a/src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoProvider.cs b/src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoProvider.cs similarity index 95% rename from src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoProvider.cs rename to src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoProvider.cs index 2bdd6909b5c..00b1c8b1dfb 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/SysctlCpuInfoProvider.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/SysctlCpuInfoProvider.cs @@ -6,7 +6,7 @@ using System; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; /// /// CPU information from output of the `sysctl -a` command. diff --git a/src/Nethermind/Nethermind.Init/Cpu/TimeInterval.cs b/src/Nethermind/Nethermind.Core/Cpu/TimeInterval.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/TimeInterval.cs rename to src/Nethermind/Nethermind.Core/Cpu/TimeInterval.cs index da44e32dc7c..690508a072f 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/TimeInterval.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/TimeInterval.cs @@ -6,9 +6,9 @@ using System.Globalization; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal readonly struct TimeInterval +public readonly struct TimeInterval { public static readonly TimeInterval Nanosecond = TimeUnit.Nanosecond.ToInterval(1L); diff --git a/src/Nethermind/Nethermind.Init/Cpu/TimeUnit.cs b/src/Nethermind/Nethermind.Core/Cpu/TimeUnit.cs similarity index 97% rename from src/Nethermind/Nethermind.Init/Cpu/TimeUnit.cs rename to src/Nethermind/Nethermind.Core/Cpu/TimeUnit.cs index dfaea152de0..821b8a90514 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/TimeUnit.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/TimeUnit.cs @@ -7,9 +7,9 @@ using System; using System.Linq; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal class TimeUnit : IEquatable +public class TimeUnit : IEquatable { public static readonly TimeUnit Nanosecond = new TimeUnit("ns", "Nanosecond", 1L); diff --git a/src/Nethermind/Nethermind.Init/Cpu/UnitPresentation.cs b/src/Nethermind/Nethermind.Core/Cpu/UnitPresentation.cs similarity index 93% rename from src/Nethermind/Nethermind.Init/Cpu/UnitPresentation.cs rename to src/Nethermind/Nethermind.Core/Cpu/UnitPresentation.cs index 900a07f78a1..bc67eaf180d 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/UnitPresentation.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/UnitPresentation.cs @@ -4,9 +4,9 @@ // Derived from https://github.com/AndreyAkinshin/perfolizer // Licensed under the MIT License -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; -internal class UnitPresentation +public class UnitPresentation { public static readonly UnitPresentation Default = new UnitPresentation(isVisible: true, 0); diff --git a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoKeyNames.cs b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoKeyNames.cs similarity index 93% rename from src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoKeyNames.cs rename to src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoKeyNames.cs index 6f690f673f9..38069667866 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoKeyNames.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoKeyNames.cs @@ -4,7 +4,7 @@ // Derived from https://github.com/dotnet/BenchmarkDotNet // Licensed under the MIT License -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class WmicCpuInfoKeyNames { diff --git a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoParser.cs b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoParser.cs similarity index 98% rename from src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoParser.cs rename to src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoParser.cs index f13d3819713..51d9b77bc79 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoParser.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoParser.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; internal static class WmicCpuInfoParser { diff --git a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoProvider.cs b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoProvider.cs similarity index 96% rename from src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoProvider.cs rename to src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoProvider.cs index 882fc2cd970..e5e4d35a27a 100644 --- a/src/Nethermind/Nethermind.Init/Cpu/WmicCpuInfoProvider.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/WmicCpuInfoProvider.cs @@ -6,7 +6,7 @@ using System; -namespace Nethermind.Init.Cpu; +namespace Nethermind.Core.Cpu; /// /// CPU information from output of the `wmic cpu get Name, NumberOfCores, NumberOfLogicalProcessors /Format:List` command. diff --git a/src/Nethermind/Nethermind.Init/Steps/LogHardwareInfo.cs b/src/Nethermind/Nethermind.Init/Steps/LogHardwareInfo.cs index 41619882327..3132f1b30ba 100644 --- a/src/Nethermind/Nethermind.Init/Steps/LogHardwareInfo.cs +++ b/src/Nethermind/Nethermind.Init/Steps/LogHardwareInfo.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Api; +using Nethermind.Core.Cpu; using ILogger = Nethermind.Logging.ILogger; namespace Nethermind.Init.Steps; @@ -25,7 +26,7 @@ public Task Execute(CancellationToken cancellationToken) try { - var cpu = Cpu.RuntimeInformation.GetCpuInfo(); + var cpu = RuntimeInformation.GetCpuInfo(); if (cpu is not null) { _logger.Info($"CPU: {cpu.ProcessorName} ({cpu.PhysicalCoreCount}C{cpu.LogicalCoreCount}T)"); From 4c64793795d2eac79cb6f13735cc14021810b67a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 4 Jun 2024 05:51:34 +0100 Subject: [PATCH 2/3] Other parallel fors --- src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs | 2 ++ src/Nethermind/Nethermind.State/PersistentStorageProvider.cs | 3 ++- src/Nethermind/Nethermind.Trie/PatriciaTree.cs | 3 ++- src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs | 3 ++- src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs | 5 +++-- src/Nethermind/Nethermind.Trie/TrieNode.Visitor.cs | 3 ++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs index e0c23df2cd3..ae56dbbfee0 100644 --- a/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs @@ -5,6 +5,7 @@ // Licensed under the MIT License using System; +using System.Threading.Tasks; namespace Nethermind.Core.Cpu; @@ -32,6 +33,7 @@ public static class RuntimeInformation } public static int PhysicalCoreCount { get; } = GetCpuInfo()?.PhysicalCoreCount ?? Environment.ProcessorCount; + public static ParallelOptions ParallelOptionsPhysicalCores { get; } = new() { MaxDegreeOfParallelism = PhysicalCoreCount }; public static bool Is64BitPlatform() => IntPtr.Size == 8; } diff --git a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs index a608cac211d..17418424657 100644 --- a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs +++ b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs @@ -18,6 +18,7 @@ namespace Nethermind.State { + using Nethermind.Core.Cpu; /// /// Manages persistent storage allowing for snapshotting and restoring /// Persists data to ITrieStore @@ -263,7 +264,7 @@ void UpdateRootHashesSingleThread() void UpdateRootHashesMultiThread() { // We can recalculate the roots in parallel as they are all independent tries - Parallel.ForEach(_storages, kvp => + Parallel.ForEach(_storages, RuntimeInformation.ParallelOptionsPhysicalCores, kvp => { if (!_toUpdateRoots.Contains(kvp.Key)) { diff --git a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs index a1305ebf9e3..83fa0d10bff 100644 --- a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs +++ b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs @@ -14,6 +14,7 @@ using System.Threading.Tasks; using Nethermind.Core; using Nethermind.Core.Buffers; +using Nethermind.Core.Cpu; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Logging; @@ -227,7 +228,7 @@ private void Commit(NodeCommitInfo nodeCommitInfo, bool skipSelf = false) if (nodesToCommit.Count >= 4) { ClearExceptions(); - Parallel.For(0, nodesToCommit.Count, i => + Parallel.For(0, nodesToCommit.Count, RuntimeInformation.ParallelOptionsPhysicalCores, i => { try { diff --git a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs index 921d5aafb01..56e7b294fcd 100644 --- a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs +++ b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs @@ -21,6 +21,7 @@ namespace Nethermind.Trie.Pruning { + using Nethermind.Core.Cpu; /// /// Trie store helps to manage trie commits block by block. /// If persistence and pruning are needed they have a chance to execute their behaviour on commits. @@ -1275,7 +1276,7 @@ void PersistNode(TrieNode n, Hash256? address, TreePath path) n.IsPersisted = true; } } - Parallel.For(0, nodesCopy.Length, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount / 2 }, i => + Parallel.For(0, nodesCopy.Length, RuntimeInformation.ParallelOptionsPhysicalCores, i => { if (cancellationToken.IsCancellationRequested) return; DirtyNodesCache.Key key = nodesCopy[i].Key; diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs index 39a33b74880..6872a3a6c3e 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Core.Buffers; +using Nethermind.Core.Cpu; using Nethermind.Core.Crypto; using Nethermind.Serialization.Rlp; using Nethermind.Trie.Pruning; @@ -174,7 +175,7 @@ private static int GetChildrenRlpLengthForBranchParallel(ITrieNodeResolver tree, private static int GetChildrenRlpLengthForBranchNonRlpParallel(ITrieNodeResolver tree, TreePath rootPath, TrieNode item, ICappedArrayPool bufferPool) { int totalLength = 0; - Parallel.For(0, BranchesCount, + Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsPhysicalCores, () => 0, (i, _, local) => { @@ -235,7 +236,7 @@ private static int GetChildrenRlpLengthForBranchNonRlp(ITrieNodeResolver tree, r private static int GetChildrenRlpLengthForBranchRlpParallel(ITrieNodeResolver tree, TreePath rootPath, TrieNode item, ICappedArrayPool? bufferPool) { int totalLength = 0; - Parallel.For(0, BranchesCount, + Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsPhysicalCores, () => 0, (i, _, local) => { diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.Visitor.cs b/src/Nethermind/Nethermind.Trie/TrieNode.Visitor.cs index ae1c79a03d3..947ae4b2f9c 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.Visitor.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.Visitor.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Nethermind.Core; using Nethermind.Core.Buffers; +using Nethermind.Core.Cpu; using Nethermind.Core.Crypto; using Nethermind.Serialization.Rlp; using Nethermind.Trie.Pruning; @@ -192,7 +193,7 @@ void VisitMultiThread(TreePath parentPath, ITreeVisitor treeVisito var copy = nodeContext; // multithreaded route - Parallel.For(0, BranchesCount, i => + Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsPhysicalCores, i => { visitContext.Semaphore.Wait(); try From d17d64a4458a0c4150f8aa3b2438993f58f310eb Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 4 Jun 2024 06:05:07 +0100 Subject: [PATCH 3/3] Some as logical cores --- src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs | 1 + src/Nethermind/Nethermind.State/PersistentStorageProvider.cs | 2 +- src/Nethermind/Nethermind.Trie/PatriciaTree.cs | 2 +- src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs index ae56dbbfee0..f1ed2b7c93d 100644 --- a/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs +++ b/src/Nethermind/Nethermind.Core/Cpu/RuntimeInformation.cs @@ -34,6 +34,7 @@ public static class RuntimeInformation public static int PhysicalCoreCount { get; } = GetCpuInfo()?.PhysicalCoreCount ?? Environment.ProcessorCount; public static ParallelOptions ParallelOptionsPhysicalCores { get; } = new() { MaxDegreeOfParallelism = PhysicalCoreCount }; + public static ParallelOptions ParallelOptionsLogicalCores { get; } = new() { MaxDegreeOfParallelism = Environment.ProcessorCount }; public static bool Is64BitPlatform() => IntPtr.Size == 8; } diff --git a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs index 17418424657..a43b892466b 100644 --- a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs +++ b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs @@ -264,7 +264,7 @@ void UpdateRootHashesSingleThread() void UpdateRootHashesMultiThread() { // We can recalculate the roots in parallel as they are all independent tries - Parallel.ForEach(_storages, RuntimeInformation.ParallelOptionsPhysicalCores, kvp => + Parallel.ForEach(_storages, RuntimeInformation.ParallelOptionsLogicalCores, kvp => { if (!_toUpdateRoots.Contains(kvp.Key)) { diff --git a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs index 83fa0d10bff..29f01170551 100644 --- a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs +++ b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs @@ -228,7 +228,7 @@ private void Commit(NodeCommitInfo nodeCommitInfo, bool skipSelf = false) if (nodesToCommit.Count >= 4) { ClearExceptions(); - Parallel.For(0, nodesToCommit.Count, RuntimeInformation.ParallelOptionsPhysicalCores, i => + Parallel.For(0, nodesToCommit.Count, RuntimeInformation.ParallelOptionsLogicalCores, i => { try { diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs index 6872a3a6c3e..b32c4f95a59 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs @@ -175,7 +175,7 @@ private static int GetChildrenRlpLengthForBranchParallel(ITrieNodeResolver tree, private static int GetChildrenRlpLengthForBranchNonRlpParallel(ITrieNodeResolver tree, TreePath rootPath, TrieNode item, ICappedArrayPool bufferPool) { int totalLength = 0; - Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsPhysicalCores, + Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsLogicalCores, () => 0, (i, _, local) => { @@ -236,7 +236,7 @@ private static int GetChildrenRlpLengthForBranchNonRlp(ITrieNodeResolver tree, r private static int GetChildrenRlpLengthForBranchRlpParallel(ITrieNodeResolver tree, TreePath rootPath, TrieNode item, ICappedArrayPool? bufferPool) { int totalLength = 0; - Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsPhysicalCores, + Parallel.For(0, BranchesCount, RuntimeInformation.ParallelOptionsLogicalCores, () => 0, (i, _, local) => {