using AsbCloudInfrastructure.EfCache; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { // use ServiceFactory to make services static void Main(/*string[] args*/) { Console.WriteLine("hit keyboard to start"); Console.ReadLine(); for (int i = 0; i < 24; i++) { var t = new Thread(_ => { for (int j = 0; j < 32; j++) //Task.Run(GetDataAsync).Wait(); GetData(); }); t.Start(); } Console.WriteLine("End of Test"); Console.ReadLine(); } static TimeSpan obso = TimeSpan.FromSeconds(5); static (long, long) GetData() { using var db = ServiceFactory.MakeContext(); var sw = System.Diagnostics.Stopwatch.StartNew(); var cs = db.TelemetryDataSaub .Where(t => t.IdTelemetry == 135) .OrderBy(t => t.DateTime) .Take(100_000) .FromCache("tds", obso, r => new { r.Pressure, r.HookWeight }) .ToList(); sw.Stop(); Console.WriteLine($"{DateTime.Now}\tth: {Thread.CurrentThread.ManagedThreadId}\ttime {sw.ElapsedMilliseconds}\tcount {cs.Count}"); GC.Collect(); Thread.Sleep(10); return (cs.Count, sw.ElapsedMilliseconds); } static async Task<(long, long)> GetDataAsync() { using var db = ServiceFactory.MakeContext(); var sw = System.Diagnostics.Stopwatch.StartNew(); var cs = (await db.TelemetryDataSaub .Where(t => t.IdTelemetry == 135) .OrderBy(t => t.DateTime) .Take(100_000) .FromCacheDictionaryAsync("tds", obso, r => (r.IdTelemetry, r.DateTime), r => new { r.Pressure, r.HookWeight })) .ToList(); sw.Stop(); Console.WriteLine($"{DateTime.Now}\tth: {Thread.CurrentThread.ManagedThreadId}\ttime {sw.ElapsedMilliseconds}\tcount {cs.Count}"); GC.Collect(); Thread.Sleep(10); return (cs.Count, sw.ElapsedMilliseconds); } } }