public static StringBuilder ReplicationSpeed(int threadCount, int time) { StringBuilder sb = new StringBuilder(); try { DBPlatform.DeleteDB(); using (var server = new ReplicableServer()) { var masterA = server.GetInstance(ReplicableServer.MasterA_DBAddress); var slaveA = server.GetInstance(ReplicableServer.SlaveA_DBAddress); var masterB = server.GetInstance(ReplicableServer.MasterB_DBAddress); var data = ((InMemoryBoxRecycler)masterA.GetBoxRecycler()).GetBoxDataAndClear(); BoxData.SlaveReplicate(slaveA, data).Assert(); BoxData.MasterReplicate(masterB, 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 = masterA.Cube(ReplicableServer.MasterB_DBAddress)) { for (var o = 0; o < objectCount; o++) { var m = new Member { ID = box.NewId(0, 1), Name = i.ToString() + "_" + o.ToString(), Age = 1 }; box.Bind("TSpeed").Insert(m); } box.Commit().Assert(); } } ); data = ((InMemoryBoxRecycler)masterA.GetBoxRecycler()).GetBoxDataAndClear(); DDebug.StartWatch(); BoxData.SlaveReplicate(slaveA, data).Assert(); slaveSec += DDebug.StopWatch().TotalSeconds; DDebug.StartWatch(); BoxData.MasterReplicate(masterB, data).Assert(); masterSec += DDebug.StopWatch().TotalSeconds; } sb.Append("\r\n\r\n*Replicate " + (threadCount * time).ToString("#,#") + " transactions, totals " + (threadCount * objectCount * time).ToString("#,#") + " objects"); var avg = (threadCount * objectCount * time) / slaveSec; sb.Append("\r\nSlaveReplicationSpeed " + slaveSec + "s, AVG " + avg.ToString("#,#") + " o/sec"); avg = (threadCount * objectCount * time) / masterSec; sb.Append("\r\nMasterReplicationSpeed " + 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 ? slaveA.Cube() : masterB.Cube()) { for (var o = 0; o < objectCount; o++) { long ID = i * objectCount + o + 1; ID += (t * threadCount * objectCount); var mem = box.Bind("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; sb.Append("\r\nLookup just after replication " + masterSec + "s, AVG " + avg.ToString("#,#") + " o/sec"); } } catch (Exception ex) { sb.Append(ex.ToString()); } return(sb); }
public static StringBuilder PMain(int threadCount) { StringBuilder sb = new StringBuilder(); sb.Append("\r\n\r\n*SpeedTest"); try { DBPlatform.DeleteDB(); using (var server = new MyServer()) { using (var db = server.GetInstance(1)) { var objectCount = 10; sb.Append("\r\nBegin Insert " + (threadCount * objectCount).ToString("#,#")); DDebug.StartWatch(); DBPlatform.For(0, threadCount, (i) => { using (var box = db.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.Bind("TSpeed").Insert(m); } box.Commit().Assert(); } } ); var sec = DDebug.StopWatch().TotalSeconds; var avg = (threadCount * objectCount) / sec; sb.Append("\r\nElapsed " + sec + "s, AVG Insert " + avg.ToString("#,#") + " o/sec"); DDebug.StartWatch(); DBPlatform.For(0, threadCount, (i) => { using (var box = db.Cube()) { for (var o = 0; o < objectCount; o++) { long ID = i * objectCount + o + 1; var mem = box.Bind("TSpeed", ID).Select <Member>(); if (mem.ID != ID) { throw new Exception(); } } } } ); sec = DDebug.StopWatch().TotalSeconds; avg = (threadCount * objectCount) / sec; sb.Append("\r\nElapsed " + sec + "s, AVG Lookup " + avg.ToString("#,#") + " o/sec"); //Parallel Query Language DDebug.StartWatch(); int count = 0; DBPlatform.For(0, threadCount, (i) => { using (var box = db.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; sb.Append("\r\nElapsed " + sec + "s, AVG Query " + avg.ToString("#,#") + " o/sec"); } } } catch (Exception ex) { sb.Append(ex.ToString()); } return(sb); }