void OpenDBSpeedTest() { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); var memStart = GC.GetTotalMemory(false); _sw.Start(); using (var fileCollection = OpenTestFileCollection()) { using (IKeyValueDB db = CreateKeyValueDB(fileCollection)) { _sw.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); var memFinish = GC.GetTotalMemory(false); Console.WriteLine("Time to open DB : {0,15}ms Memory: {1}KB {2}KB", _sw.Elapsed.TotalMilliseconds, (memFinish - memStart) / 1024, Process.GetCurrentProcess().WorkingSet64 / 1024); Console.WriteLine(db.CalcStats()); _sw.Restart(); } } _sw.Stop(); Console.WriteLine("Time to close DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); }
public void Run() { Initialize(); var cancelationSource = new CancellationTokenSource(); var eventTask = new Task(() => { var cancelation = cancelationSource.Token; while (!cancelation.IsCancellationRequested) { } }); var consoleTask = new Task(() => { var cancelation = cancelationSource.Token; while (!cancelation.IsCancellationRequested) { switch (Console.ReadLine()) { case "e": cancelationSource.Cancel(); break; case "m": Console.WriteLine($"GC Memory: {GC.GetTotalMemory(false)} Working set: {Process.GetCurrentProcess().WorkingSet64}"); break; case "s": Console.WriteLine(_kvdb.CalcStats()); break; } } }); Task.WaitAll(eventTask, consoleTask); Dispose(); }
public string CalcStats() { return(_keyValueDB.CalcStats()); }
public void HugeTest() { const int keyCount = 100; using (var fileCollection = CreateTestFileCollection()) { _sw.Start(); using (IKeyValueDB db = CreateKeyValueDB(fileCollection, new NoCompressionStrategy())) { var key = new byte[100]; var value = new byte[100000000]; for (int i = 0; i < keyCount; i++) { using (var tr = db.StartTransaction()) { key[0] = (byte)(i / 100); key[1] = (byte)(i % 100); value[100] = (byte)(i / 100); value[200] = (byte)(i % 100); tr.CreateOrUpdateKeyValue(key, value); tr.Commit(); } } } _sw.Stop(); Console.WriteLine("Time to create 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); _sw.Restart(); using (IKeyValueDB db = new KeyValueDB(fileCollection)) { _sw.Stop(); Console.WriteLine("Time to open 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); _sw.Restart(); var key = new byte[100]; for (int i = 0; i < keyCount; i++) { using (var tr = db.StartTransaction()) { key[0] = (byte)(i / 100); key[1] = (byte)(i % 100); tr.FindExactKey(key); var value = tr.GetValueAsByteArray(); if (value[100] != (byte)(i / 100)) { throw new InvalidDataException(); } if (value[200] != (byte)(i % 100)) { throw new InvalidDataException(); } } } _sw.Stop(); Console.WriteLine("Time to read all values 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); Console.WriteLine(db.CalcStats()); } _sw.Restart(); using (IKeyValueDB db = CreateKeyValueDB(fileCollection)) { _sw.Stop(); Console.WriteLine("Time to open2 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); _sw.Restart(); var key = new byte[100]; for (int i = 0; i < keyCount; i++) { using (var tr = db.StartTransaction()) { key[0] = (byte)(i / 100); key[1] = (byte)(i % 100); tr.FindExactKey(key); var value = tr.GetValueAsByteArray(); if (value[100] != (byte)(i / 100)) { throw new InvalidDataException(); } if (value[200] != (byte)(i % 100)) { throw new InvalidDataException(); } } } _sw.Stop(); Console.WriteLine("Time to read2 all values 10GB DB: {0,15}ms", _sw.Elapsed.TotalMilliseconds); Console.WriteLine(db.CalcStats()); } } }