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 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(); }