public static void ReplicationSpeed(int threadCount, int time) { DBPlatform.DeleteDB(); int MasterA_DBAddress = 10; int MasterB_DBAddress = 20; int SlaveA_DBAddress = -10; var db_masterA = new DB(MasterA_DBAddress); db_masterA.GetConfig().EnsureTable <Member>("TSpeed", "ID"); db_masterA.SetBoxRecycler(new MemoryBoxRecycler()); var auto_masterA = db_masterA.Open(MasterB_DBAddress); var db_slave = new DB(SlaveA_DBAddress); var auto_slave = db_slave.Open(); var db_masterB = new DB(MasterB_DBAddress); db_masterB.GetConfig().EnsureTable <Member>("TSpeed", "ID"); var auto_masterB = db_masterB.Open(); var data = ((MemoryBoxRecycler)auto_masterA.GetDatabase().GetBoxRecycler()).AsBoxData(); BoxData.SlaveReplicate(auto_slave.GetDatabase(), data).Assert(); BoxData.MasterReplicate(auto_masterB.GetDatabase(), data).Assert(); var objectCount = 10; double slaveSec = 0; double masterSec = 0; for (var t = 0; t < time; t++) { DBPlatform.For(0, threadCount, (i) => { using (var box = auto_masterA.Cube()) { for (var o = 0; o < objectCount; o++) { var m = new Member { ID = box.NewId(0, 1), Name = i.ToString() + "_" + o.ToString(), Age = 1 }; box["TSpeed"].Insert(m); } box.Commit().Assert(); } }); data = ((MemoryBoxRecycler)auto_masterA.GetDatabase().GetBoxRecycler()).AsBoxData(); DDebug.StartWatch(); BoxData.SlaveReplicate(auto_slave.GetDatabase(), data).Assert(); slaveSec += DDebug.StopWatch().TotalSeconds; DDebug.StartWatch(); BoxData.MasterReplicate(auto_masterB.GetDatabase(), data).Assert(); masterSec += DDebug.StopWatch().TotalSeconds; } WriteLine("Replicate " + (threadCount * time).ToString("#,#") + " transactions, totals " + (threadCount * objectCount * time).ToString("#,#") + " objects"); var avg = (threadCount * objectCount * time) / slaveSec; WriteLine("SlaveSpeed " + slaveSec + "s, AVG " + avg.ToString("#,#") + " o/sec"); avg = (threadCount * objectCount * time) / masterSec; WriteLine("MasterSpeed " + masterSec + "s, AVG " + avg.ToString("#,#") + " o/sec"); int count = 0; DDebug.StartWatch(); for (var t = 0; t < time; t++) { DBPlatform.For(0, threadCount, (i) => { for (var dbc = 0; dbc < 2; dbc++) { using (var box = dbc == 0 ? auto_slave.Cube() : auto_masterB.Cube()) { for (var o = 0; o < objectCount; o++) { long ID = i * objectCount + o + 1; ID += (t * threadCount * objectCount); var mem = box["TSpeed", ID].Select <Member>(); if (mem.ID != ID) { throw new Exception(); } Interlocked.Add(ref count, mem.Age); } } } }); } if (count != (threadCount * objectCount * time * 2)) { throw new Exception(); } masterSec = DDebug.StopWatch().TotalSeconds; avg = count / masterSec; WriteLine("Lookup after replication " + masterSec + "s, AVG " + avg.ToString("#,#") + " o/sec"); auto_masterA.GetDatabase().Dispose(); auto_slave.GetDatabase().Dispose(); auto_masterB.GetDatabase().Dispose(); }
public static void SpeedTest(int threadCount) { DBPlatform.DeleteDB(); var db = new DB(1); db.GetConfig().EnsureTable <Member>("TSpeed", "ID"); var dbConfig = db.GetConfig().DBConfig; //Cache //dbConfig.CacheLength = dbConfig.MB(512); //File //dbConfig.FileIncSize = (int)dbConfig.MB(4); //Thread //dbConfig.ReadStreamCount = 8; var auto = db.Open(); WriteLine("Speed"); var objectCount = 10; WriteLine("Begin Insert " + (threadCount * objectCount).ToString("#,#")); DDebug.StartWatch(); DBPlatform.For(0, threadCount, (i) => { using (var box = auto.Cube()) { for (var o = 0; o < objectCount; o++) { var m = new Member { ID = box.NewId(0, 1), Name = i.ToString() + "_" + o.ToString(), Age = 1 }; box["TSpeed"].Insert(m); } box.Commit().Assert(); } }); var sec = DDebug.StopWatch().TotalSeconds; var avg = (threadCount * objectCount) / sec; WriteLine("Elapsed " + sec + "s, AVG Insert " + avg.ToString("#,#") + " o/sec"); DDebug.StartWatch(); DBPlatform.For(0, threadCount, (i) => { using (var box = auto.Cube()) { for (var o = 0; o < objectCount; o++) { long ID = i * objectCount + o + 1; var mem = box["TSpeed", ID].Select <Member>(); if (mem.ID != ID) { throw new Exception(); } } } }); sec = DDebug.StopWatch().TotalSeconds; avg = (threadCount * objectCount) / sec; WriteLine("Elapsed " + sec + "s, AVG Lookup " + avg.ToString("#,#") + " o/sec"); DDebug.StartWatch(); int count = 0; DBPlatform.For(0, threadCount, (i) => { using (var box = auto.Cube()) { var tspeed = box.Select <Member>("from TSpeed where ID>=? & ID<=?", (long)(i * objectCount + 1), (long)(i * objectCount + objectCount)); foreach (var m in tspeed) { // age == 1 Interlocked.Add(ref count, m.Age); } } }); if (count != (threadCount * objectCount)) { throw new Exception(count.ToString()); } sec = DDebug.StopWatch().TotalSeconds; avg = count / sec; WriteLine("Elapsed " + sec + "s, AVG Query " + avg.ToString("#,#") + " o/sec"); db.Dispose(); }