public void RandomizedThreadedLookups() { string path = Path.GetFullPath("TestData\\RandomizedThreadedLookups"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <KeyValuePair <Key, Value> > items = new List <KeyValuePair <Key, Value> > (); int num_items = 10000; var mt = new MemTable(); for (int i = 0; i < num_items; i++) { var k0 = Key.Random(40); var v0 = Value.Random(200); mt.Add(k0, v0); items.Add(new KeyValuePair <Key, Value> (k0, v0)); } mt.WriteToSortedBlockTable("TestData\\RandomizedThreadedLookups", 10, 10); var cache = new RazorCache(); var sbt = new SortedBlockTable(cache, "TestData\\RandomizedThreadedLookups", 10, 10); var indexCache = new RazorCache(); List <Thread> threads = new List <Thread> (); for (int t = 0; t < 10; t++) { threads.Add(new Thread((num) => { for (int k = 0; k < num_items / 10; k++) { var pair = items [k * (int)num]; Value value; Assert.IsTrue(SortedBlockTable.Lookup("TestData\\RandomizedThreadedLookups", 10, 10, indexCache, pair.Key, out value, ExceptionHandling.ThrowAll, null)); Assert.AreEqual(pair.Value, value); } })); } var timer = new Stopwatch(); timer.Start(); int threadNum = 0; threads.ForEach((t) => t.Start(threadNum++)); threads.ForEach((t) => t.Join()); timer.Stop(); Console.WriteLine("Randomized (threaded) read sbt table at a throughput of {0} MB/s (avg {1} ms per lookup)", (double)mt.Size / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0), (double)timer.Elapsed.TotalSeconds / (double)num_items); sbt.Close(); }
public void RandomizedLookups() { string path = Path.GetFullPath("TestData\\RandomizedKeys"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <KeyValuePair <Key, Value> > items = new List <KeyValuePair <Key, Value> > (); int num_items = 10000; var mt = new MemTable(); for (int i = 0; i < num_items; i++) { var k0 = Key.Random(40); var v0 = Value.Random(200); mt.Add(k0, v0); items.Add(new KeyValuePair <Key, Value> (k0, v0)); } mt.WriteToSortedBlockTable("TestData\\RandomizedKeys", 10, 10); var cache = new RazorCache(); var sbt = new SortedBlockTable(cache, "TestData\\RandomizedKeys", 10, 10); var indexCache = new RazorCache(); var timer = new Stopwatch(); timer.Start(); foreach (var pair in items) { Value value; Assert.IsTrue(SortedBlockTable.Lookup("TestData\\RandomizedKeys", 10, 10, indexCache, pair.Key, out value, ExceptionHandling.ThrowAll, null)); Assert.AreEqual(pair.Value, value); } timer.Stop(); Value randomValue; Assert.IsFalse(SortedBlockTable.Lookup("TestData\\RandomizedKeys", 10, 10, indexCache, Key.Random(40), out randomValue, ExceptionHandling.ThrowAll, null)); Console.WriteLine("Randomized read sbt table at a throughput of {0} MB/s (avg {1} ms per lookup)", (double)mt.Size / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0), (double)timer.Elapsed.TotalSeconds / (double)num_items); sbt.Close(); }