forked from NethermindEth/nethermind
-
Notifications
You must be signed in to change notification settings - Fork 0
Imapp benchmark #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
JacekGlen
wants to merge
6
commits into
master
Choose a base branch
from
imapp_benchmark
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40fe5b3
Add benchmark and measurement projects
a202f92
Add imap projects to solution
6cbec34
Remove unnecessary testdata submodule
pdobacz 3dfa89b
Remove redundant submodules
d27fcea
Code review comments resolution
0b29a85
Merge branch 'master' into imapp_benchmark
JacekGlen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Nethermind/Imapp.Benchmark.Runner/BenchmarkNullExporter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using BenchmarkDotNet.Exporters; | ||
| using BenchmarkDotNet.Loggers; | ||
| using BenchmarkDotNet.Reports; | ||
|
|
||
| namespace Imapp.Benchmark.Runner | ||
| { | ||
| public class BenchmarkNullExporter : IExporter | ||
| { | ||
| public string Name => "ImappNullExporter"; | ||
|
|
||
| public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger) | ||
| { | ||
| return Enumerable.Empty<string>(); | ||
| } | ||
|
|
||
| public void ExportToLog(Summary summary, ILogger logger) | ||
| { | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/Nethermind/Imapp.Benchmark.Runner/BenchmarkNullLogger.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using BenchmarkDotNet.Loggers; | ||
|
|
||
| namespace Imapp.Benchmark.Runner | ||
| { | ||
| public class BenchmarkNullLogger : ILogger | ||
| { | ||
| public string Id => "ImappNullLogger"; | ||
|
|
||
| public int Priority => 1; | ||
|
|
||
| public void Flush() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public void Write(LogKind logKind, string text) | ||
| { | ||
| } | ||
|
|
||
| public void WriteLine() | ||
| { | ||
| } | ||
|
|
||
| public void WriteLine(LogKind logKind, string text) | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
src/Nethermind/Imapp.Benchmark.Runner/EvmByteCodeBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System; | ||
| using BenchmarkDotNet.Attributes; | ||
| using Nethermind.Core; | ||
| using Nethermind.Core.Crypto; | ||
| using Nethermind.Core.Extensions; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.Db; | ||
| using Nethermind.Evm.CodeAnalysis; | ||
| using Nethermind.Specs; | ||
| using Nethermind.Evm.Tracing; | ||
| using Nethermind.Int256; | ||
| using Nethermind.Logging; | ||
| using Nethermind.State; | ||
| using Nethermind.Trie.Pruning; | ||
| using Nethermind.Evm; | ||
| using Nethermind.Evm.Benchmark; | ||
|
|
||
| namespace Imapp.Benchmark.Runner | ||
| { | ||
| [MaxWarmupCount(10)] | ||
| [MaxIterationCount(40)] | ||
| [MemoryDiagnoser] | ||
| public class EvmByteCodeBenchmark | ||
| { | ||
| public static byte[] ByteCode { get; set; } | ||
|
|
||
| private IReleaseSpec _spec = MainnetSpecProvider.Instance.GetSpec(MainnetSpecProvider.IstanbulBlockNumber); | ||
| private ITxTracer _txTracer = NullTxTracer.Instance; | ||
| private ExecutionEnvironment _environment; | ||
| private IVirtualMachine _virtualMachine; | ||
| private BlockHeader _header = new BlockHeader(Keccak.Zero, Keccak.Zero, Address.Zero, UInt256.One, MainnetSpecProvider.IstanbulBlockNumber, Int64.MaxValue, UInt256.One, Bytes.Empty); | ||
| private IBlockhashProvider _blockhashProvider = new TestBlockhashProvider(); | ||
| private EvmState _evmState; | ||
| private StateProvider _stateProvider; | ||
| private StorageProvider _storageProvider; | ||
| private WorldState _worldState; | ||
|
|
||
| [GlobalSetup] | ||
| public void GlobalSetup() | ||
| { | ||
| ByteCode = Bytes.FromHexString(Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE") ?? string.Empty); | ||
| //Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}"); | ||
|
|
||
| TrieStore trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance)); | ||
| IKeyValueStore codeDb = new MemDb(); | ||
|
|
||
| _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance)); | ||
| _stateProvider.CreateAccount(Address.Zero, 1000.Ether()); | ||
| _stateProvider.Commit(_spec); | ||
|
|
||
| _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance)); | ||
|
|
||
| _worldState = new WorldState(_stateProvider, _storageProvider); | ||
|
|
||
| _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance); | ||
|
|
||
| _environment = new ExecutionEnvironment | ||
| { | ||
| ExecutingAccount = Address.Zero, | ||
| CodeSource = Address.Zero, | ||
| Caller = Address.Zero, | ||
| CodeInfo = new CodeInfo(ByteCode), | ||
| Value = 0, | ||
| TransferValue = 0, | ||
| TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0) | ||
| }; | ||
| } | ||
|
|
||
| [IterationSetup] | ||
| public void Setup() | ||
| { | ||
| _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void ExecuteCode() | ||
| { | ||
| _virtualMachine.Run(_evmState, _worldState, _txTracer); | ||
| } | ||
|
|
||
| [IterationCleanup] | ||
| public void Cleanup() | ||
| { | ||
| _stateProvider.Reset(); | ||
| _storageProvider.Reset(); | ||
| } | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/Nethermind/Imapp.Benchmark.Runner/Imapp.Benchmark.Runner.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
| <PackageReference Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.22272.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Nethermind.Benchmark\Nethermind.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.EthereumTests.Benchmark\Nethermind.EthereumTests.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Evm.Benchmark\Nethermind.Evm.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.JsonRpc.Benchmark\Nethermind.JsonRpc.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Network.Benchmark\Nethermind.Network.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Precompiles.Benchmark\Nethermind.Precompiles.Benchmark.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using BenchmarkDotNet.Configs; | ||
| using BenchmarkDotNet.Running; | ||
| using System.CommandLine; | ||
|
|
||
| namespace Imapp.Benchmark.Runner | ||
| { | ||
| class Program | ||
| { | ||
| static int Main(string bytecode, int sampleSize = 1, bool printCSV = false) | ||
| { | ||
| var config = new ManualConfig() | ||
| //.WithOptions(ConfigOptions.DisableOptimizationsValidator) | ||
| .WithOptions(ConfigOptions.DisableLogFile) | ||
| .AddExporter(new BenchmarkNullExporter()); | ||
|
|
||
| if (printCSV) | ||
| { | ||
| config = config.AddLogger(new BenchmarkNullLogger()); | ||
| } | ||
| else | ||
| { | ||
| config = config.AddLogger(BenchmarkDotNet.Loggers.ConsoleLogger.Default); | ||
| } | ||
|
|
||
| if (String.IsNullOrEmpty(bytecode)) | ||
| { | ||
| throw new Exception("Bytecode cannot be empty"); | ||
| } | ||
|
|
||
| for (int i = 1; i <= sampleSize; ++i) | ||
| { | ||
| Environment.SetEnvironmentVariable("NETH.BENCHMARK.BYTECODE", "00" + bytecode); | ||
| //Console.WriteLine("Code: " + Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE")); | ||
| var r1 = BenchmarkRunner.Run<EvmByteCodeBenchmark>(config); | ||
|
|
||
| Environment.SetEnvironmentVariable("NETH.BENCHMARK.BYTECODE", bytecode); | ||
| //Console.WriteLine("Code: " + Environment.GetEnvironmentVariable("NETH.BENCHMARK.BYTECODE")); | ||
| var r2 = BenchmarkRunner.Run<EvmByteCodeBenchmark>(config); | ||
|
|
||
| OutputOverheadResults(i, r1, r2); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| private static void OutputOverheadResults(int sampleId, BenchmarkDotNet.Reports.Summary rEmpty, BenchmarkDotNet.Reports.Summary rActual) | ||
| { | ||
| var reportEmpty = rEmpty.Reports[0]; | ||
|
JacekGlen marked this conversation as resolved.
|
||
| var reportActual = rActual.Reports[0]; | ||
| var overheadTime = reportEmpty.ResultStatistics.Mean; | ||
|
|
||
| var loopExecutionTime = reportActual.ResultStatistics.Mean - reportEmpty.ResultStatistics.Mean; | ||
| var totalTime = reportActual.ResultStatistics.Mean; | ||
|
|
||
| var memAllocPerOp = reportActual.GcStats.GetBytesAllocatedPerOperation(reportActual.BenchmarkCase); | ||
|
|
||
| Console.WriteLine($"{sampleId},{reportActual.ResultStatistics.N},{overheadTime},{loopExecutionTime},{totalTime},{reportActual.ResultStatistics.StandardDeviation},{reportActual.GcStats.TotalOperations},{memAllocPerOp}"); | ||
| } | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
src/Nethermind/Imapp.Measurement.Runner/EvmByteCodeBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| using System; | ||
| using BenchmarkDotNet.Attributes; | ||
| using Nethermind.Core; | ||
| using Nethermind.Core.Crypto; | ||
| using Nethermind.Core.Extensions; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.Db; | ||
| using Nethermind.Evm.CodeAnalysis; | ||
| using Nethermind.Specs; | ||
| using Nethermind.Evm.Tracing; | ||
| using Nethermind.Int256; | ||
| using Nethermind.Logging; | ||
| using Nethermind.State; | ||
| using Nethermind.Trie.Pruning; | ||
| using Nethermind.Evm; | ||
| using Nethermind.Evm.Benchmark; | ||
|
|
||
| namespace Imapp.Measurement.Runner | ||
| { | ||
| public class EvmByteCodeBenchmark | ||
| { | ||
| public static byte[] ByteCode { get; set; } | ||
|
|
||
| private IReleaseSpec _spec = MainnetSpecProvider.Instance.GetSpec(MainnetSpecProvider.IstanbulBlockNumber); | ||
| private ITxTracer _txTracer = NullTxTracer.Instance; | ||
| private ExecutionEnvironment _environment; | ||
| private IVirtualMachine _virtualMachine; | ||
| private BlockHeader _header = new BlockHeader(Keccak.Zero, Keccak.Zero, Address.Zero, UInt256.One, MainnetSpecProvider.IstanbulBlockNumber, Int64.MaxValue, UInt256.One, Bytes.Empty); | ||
| private IBlockhashProvider _blockhashProvider = new TestBlockhashProvider(); | ||
| private EvmState _evmState; | ||
| private StateProvider _stateProvider; | ||
| private StorageProvider _storageProvider; | ||
| private WorldState _worldState; | ||
|
|
||
| public void GlobalSetup(string bytecode) | ||
| { | ||
| ByteCode = Bytes.FromHexString(bytecode); | ||
| //Console.WriteLine($"Running benchmark for bytecode {ByteCode?.ToHexString()}"); | ||
|
|
||
| TrieStore trieStore = new(new MemDb(), new OneLoggerLogManager(NullLogger.Instance)); | ||
| IKeyValueStore codeDb = new MemDb(); | ||
|
|
||
| _stateProvider = new StateProvider(trieStore, codeDb, new OneLoggerLogManager(NullLogger.Instance)); | ||
| _stateProvider.CreateAccount(Address.Zero, 1000.Ether()); | ||
| _stateProvider.Commit(_spec); | ||
|
|
||
| _storageProvider = new StorageProvider(trieStore, _stateProvider, new OneLoggerLogManager(NullLogger.Instance)); | ||
|
|
||
| _worldState = new WorldState(_stateProvider, _storageProvider); | ||
|
|
||
| _virtualMachine = new VirtualMachine(_blockhashProvider, MainnetSpecProvider.Instance, LimboLogs.Instance); | ||
|
|
||
| _environment = new ExecutionEnvironment | ||
| { | ||
| ExecutingAccount = Address.Zero, | ||
| CodeSource = Address.Zero, | ||
| Caller = Address.Zero, | ||
| CodeInfo = new CodeInfo(ByteCode), | ||
| Value = 0, | ||
| TransferValue = 0, | ||
| TxExecutionContext = new TxExecutionContext(_header, Address.Zero, 0) | ||
| }; | ||
| } | ||
|
|
||
| public void Setup() | ||
| { | ||
| _evmState = new EvmState(long.MaxValue, _environment, ExecutionType.Transaction, true, _worldState.TakeSnapshot(), false); | ||
| } | ||
|
|
||
| public void ExecuteCode() | ||
| { | ||
| _virtualMachine.Run(_evmState, _worldState, _txTracer); | ||
| } | ||
|
|
||
| public void Cleanup() | ||
| { | ||
| _stateProvider.Reset(); | ||
| _storageProvider.Reset(); | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/Nethermind/Imapp.Measurement.Runner/Imapp.Measurement.Runner.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
| <PackageReference Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.22272.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Nethermind.Benchmark\Nethermind.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.EthereumTests.Benchmark\Nethermind.EthereumTests.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Evm.Benchmark\Nethermind.Evm.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.JsonRpc.Benchmark\Nethermind.JsonRpc.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Network.Benchmark\Nethermind.Network.Benchmark.csproj" /> | ||
| <ProjectReference Include="..\Nethermind.Precompiles.Benchmark\Nethermind.Precompiles.Benchmark.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
43 changes: 43 additions & 0 deletions
43
src/Nethermind/Imapp.Measurement.Runner/InstrumentationLogger.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Imapp.Measurement.Runner | ||
| { | ||
| public class InstrumentationLogger | ||
| { | ||
| private List<InstrumentationLoggerItem> items = new List<InstrumentationLoggerItem>(); | ||
|
|
||
| public void Add(InstrumentationLoggerItem item) | ||
| { | ||
| if (item.End < item.Start) throw new Exception("Invalid measurement"); | ||
| items.Add(item); | ||
| } | ||
|
|
||
| public void PrintResults() | ||
| { | ||
| foreach (var item in items) | ||
| { | ||
| var ticksLength = item.End - item.Start; | ||
|
|
||
| Console.WriteLine($"{item.SampleId},{TicksToNs(ticksLength)}"); | ||
| } | ||
| } | ||
|
|
||
| private double TicksToNs(long ticks) | ||
| { | ||
| double ns = 1000000000.0 * (double)ticks / Stopwatch.Frequency; | ||
| return ns; | ||
| } | ||
| } | ||
|
|
||
| public struct InstrumentationLoggerItem | ||
| { | ||
| public int SampleId { get; set; } | ||
| public long Start { get; set; } | ||
| public long End { get; set; } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know this very well, but doesn't this belong to
Teardown? it appears as if we were measuring theseReset's, while I think we shouldn't.