public Benchmarks(IStateStore stateStore, IChainCreationService chainCreationService, IChainContextService chainContextService, ISmartContractService smartContractService, ILogger logger, IFunctionMetadataService functionMetadataService, BenchmarkOptions options, IExecutingService executingService) { ChainId = Hash.Generate(); _stateStore = stateStore; _chainCreationService = chainCreationService; _smartContractService = smartContractService; _logger = logger; _options = options; _executingService = executingService; _servicePack = new ServicePack { ChainContextService = chainContextService, SmartContractService = _smartContractService, ResourceDetectionService = new ResourceUsageDetectionService(functionMetadataService), StateStore = _stateStore }; _dataGenerater = new TransactionDataGenerator(options); byte[] code; using (FileStream file = File.OpenRead(Path.GetFullPath(options.DllDir + "/" + options.ContractDll))) { code = file.ReadFully(); } _contractHash = Prepare(code).Result; }
public TransactionDataGenerator(BenchmarkOptions opts) { if (opts.BenchmarkMethod == BenchmarkMethod.EvenGroup) { if (ReadFromFile(opts.AccountFileDir) == false) { GenerateHashes(opts); } } else if (opts.BenchmarkMethod == BenchmarkMethod.GenerateAccounts) { GenerateHashes(opts); } }
private void GenerateHashes(BenchmarkOptions opts) { if (opts.GroupRange.Count() != 2 && opts.GroupRange.ElementAt(0) <= opts.GroupRange.ElementAt(1)) { Console.WriteLine("Group range option required, and should be [a, b] where a <= b"); return; } _maxTxNumber = opts.TxNumber; _maxGroupNumber = opts.GroupRange.ElementAt(1); Console.WriteLine($"Generate account for {_maxTxNumber} from scratch"); KeyList = new List <Address>(); for (int i = 0; i < _maxTxNumber + _maxGroupNumber; i++) { KeyList.Add(Address.FromRawBytes(Hash.Generate().ToByteArray())); } }
public static async Task Main(string[] args) { BenchmarkOptions opts = null; Parser.Default.ParseArguments <BenchmarkOptions>(args) .WithParsed(o => { opts = o; }) .WithNotParsed(errs => {}); if (opts == null) { return; } if (opts.BenchmarkMethod == BenchmarkMethod.EvenGroup) { if (opts.SdkDir == null) { opts.SdkDir = Directory.GetCurrentDirectory(); Console.WriteLine("No Sdk directory in arg, choose current directory: " + opts.SdkDir); } if (opts.DllDir == null) { opts.DllDir = Directory.GetCurrentDirectory(); Console.WriteLine("No dll directory in arg, choose current directory: " + opts.DllDir); } if (!Directory.Exists(Path.GetFullPath(opts.SdkDir))) { Console.WriteLine("directory " + Path.GetFullPath(opts.SdkDir) + " not exist"); return; } if (!File.Exists(Path.GetFullPath(Path.Combine(opts.DllDir, opts.ContractDll)))) { Console.WriteLine( Path.GetFullPath(Path.Combine(opts.DllDir, opts.ContractDll) + " not exist")); return; } if (!File.Exists(Path.GetFullPath(Path.Combine(opts.DllDir, opts.ZeroContractDll)))) { Console.WriteLine( Path.GetFullPath(Path.Combine(opts.DllDir, opts.ZeroContractDll) + " not exist")); return; } if (opts.GroupRange.Count() != 2 || opts.GroupRange.ElementAt(0) > opts.GroupRange.ElementAt(1)) { Console.WriteLine( "please input 2 number to indicate the lower and upper bounds, where lower bound is lower than upper bound"); return; } if (opts.ConcurrencyLevel.HasValue) { ActorConfig.Instance.ConcurrencyLevel = opts.ConcurrencyLevel.Value; } //enable parallel feature for benchmark ParallelConfig.Instance.IsParallelEnable = true; var builder = new ContainerBuilder(); //builder.RegisterModule(new MainModule()); builder.RegisterModule(new DatabaseAutofacModule()); builder.RegisterModule(new LoggerAutofacModule()); builder.RegisterModule(new ChainAutofacModule()); builder.RegisterModule(new KernelAutofacModule()); builder.RegisterModule(new SmartContractAutofacModule()); builder.RegisterType <Benchmarks>().WithParameter("options", opts); var runner = new SmartContractRunner(opts.SdkDir); SmartContractRunnerFactory smartContractRunnerFactory = new SmartContractRunnerFactory(); smartContractRunnerFactory.AddRunner(0, runner); smartContractRunnerFactory.AddRunner(1, runner); builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance(); if (ParallelConfig.Instance.IsParallelEnable) { builder.RegisterType <Grouper>().As <IGrouper>(); builder.RegisterType <ServicePack>().As <ServicePack>().PropertiesAutowired(); builder.RegisterType <ActorEnvironment>().As <IActorEnvironment>().SingleInstance(); builder.RegisterType <ParallelTransactionExecutingService>().As <IExecutingService>(); } else { builder.RegisterType <SimpleExecutingService>().As <IExecutingService>(); } var container = builder.Build(); if (container == null) { Console.WriteLine("IoC setup failed"); return; } if (!CheckDbConnect(container)) { Console.WriteLine("Database connection failed"); return; } using (var scope = container.BeginLifetimeScope()) { if (ParallelConfig.Instance.IsParallelEnable) { var actorEnv = scope.Resolve <IActorEnvironment>(); try { actorEnv.InitActorSystem(); } catch (Exception e) { Console.WriteLine(e); } } var benchmarkTps = scope.Resolve <Benchmarks>(); await benchmarkTps.InitContract(); Thread.Sleep(200); //sleep 200 ms to let async console print in order await benchmarkTps.BenchmarkEvenGroup(); } } else if (opts.BenchmarkMethod == BenchmarkMethod.GenerateAccounts) { var dataGenerator = new TransactionDataGenerator(opts); dataGenerator.PersistAddrsToFile(opts.AccountFileDir); } Console.WriteLine("\n\nPress any key to continue "); Console.ReadKey(); }