// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddGrpc(); services.AddSingleton(sp => { var lifetimeEvents = sp.GetService <IHostApplicationLifetime>(); var ekati = new Ekati.GrpcFileStore(new Config( Convert.ToInt32(1), //Environment.ProcessorCount * .75), FSharpFunc <string, Unit> .FromConverter( input => { return(null); }), false, AppMetrics .CreateDefaultBuilder() .Build())) as IStorage; lifetimeEvents.ApplicationStopping.Register(() => { Console.WriteLine("Ekati got shutdown event. Calling Stop"); ekati.Stop(); Console.WriteLine("Ekati got shutdown event. Stop Finished"); }); return(ekati); }); services.AddGrpc(); //services.AddGrpcWeb(o => o.GrpcWebEnabled = true); // services.AddCors(o => // { // o.AddPolicy("MyPolicy", builder => // { // builder.WithOrigins("localhost:5001","localhost:5000"); // builder.WithMethods("POST,OPTIONS"); // builder.AllowAnyHeader(); // builder.WithExposedHeaders("Grpc-Status", "Grpc-Message"); // }); // }); }
public static async Task <string> Benchmark(int count, int followscount) { var config = TestConfig(); var firstWritten = false; var g = new GrpcFileStore(config); g.collectSystemMetrics(); var envFile = "./env.info"; using var ef = new FileStream(envFile, FileMode.Create); var envms1 = new MemoryStream(); var root = config.Metrics as IMetricsRoot; root.DefaultOutputEnvFormatter.WriteAsync(envms1, root.EnvironmentInfo).Wait(); var envms2 = new MemoryStream(); void report(FileStream file) { g.collectSystemMetrics(); var snap = config.Metrics.Snapshot.Get(); foreach (var formatter in root.OutputMetricsFormatters) { if (formatter.MediaType.Type == "application") { using var ms = new MemoryStream(); if (firstWritten) { var bytes = Encoding.UTF8.GetBytes(","); ms.Write(bytes, 0, bytes.Length); } else { firstWritten = true; } formatter.WriteAsync(ms, snap).Wait(); var a = ms.ToArray(); file.Write(a, 0, a.Length); file.Flush(); } } } // add some extra goodies. // Processor Count void emitMore <T>(string name, T data) { var bytes = Encoding.UTF8.GetBytes($"{name} = {data}"); envms2.Write(bytes, 0, bytes.Length); } emitMore("Processor Count", Environment.ProcessorCount); emitMore("System Page Size", Environment.SystemPageSize); var a = envms1.ToArray(); ef.Write(a, 0, a.Length); var b = envms2.ToArray(); ef.Write(b, 0, b.Length); ef.Flush(); var reportFile = $"./report-{count}-{followscount}.{DateTime.Now.ToFileTime()}.json"; var f = new FileStream(reportFile, FileMode.Create); var bytesOpen = Encoding.UTF8.GetBytes("["); f.Write(bytesOpen, 0, bytesOpen.Length); var duration = TimeSpan.FromSeconds(10); var timer = Stopwatch.StartNew(); var stop = false; var reporter = Task.Run(async() => { while (!stop) { report(f); await Task.Delay(5000); } }); var t1 = ValueTask.CompletedTask; var t2 = ValueTask.CompletedTask; var ct = 0; var enu = BuildLotsNodes(); using (var sess = g.Session()) { while (timer.Elapsed < duration) { ct++; var current = enu.Take(1000); while (t1.IsCompleted == false) { t1.AsTask().Wait(10000); } t1 = t2; t2 = sess.Upsert(current); } } g.Flush(); Thread.Sleep(10000); // now for the read test var readTimer = Stopwatch.StartNew(); count = 0; using (var sess = g.Session()) { var readEnu = sess.ScanAll().GetEnumerator(); while (readTimer.Elapsed < duration) { if (readEnu.MoveNext()) { count++; var n = readEnu.Current; } } } stop = true; await reporter; g.Stop(); bytesOpen = Encoding.UTF8.GetBytes("]"); f.Write(bytesOpen, 0, bytesOpen.Length); f.Flush(); f.Dispose(); return(reportFile); }