internal static bool RemoteTestCase() { typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null); using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer)) { if (server.Start()) { using (memoryDatabaseModelTable <identity> .remote table = new memoryDatabaseModelTable <identity> .remote(new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer), cache = new identityArray <identity>())) { updateMember = table.CreateMemberMap().Append(value => value.Int); cache.WaitLoad(); if (cache.Count == 0) { identity int1 = table.Insert(new identity { Int = 1, String = "A大A" }, false); identity intOld2 = new identity { Int = 2 }; identity int2 = table.Insert(intOld2); identity int4 = table.Insert(new identity { Int = 4 }); if (int1 == null) { return(false); } if (int2 == null) { return(false); } if (int4 == null) { return(false); } intOld2.Int = 3; identity int3 = table.Update(intOld2, updateMember); if (int3 == null) { return(false); } identity delete = table.Delete(int4.Id); if (delete == null) { return(false); } return(check(table, false)); } return(check(table, true)); } } } return(false); }
/// <summary> /// 性能测试 /// </summary> public static void Test() { typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null); fastCSharp.code.cSharp.tcpServer tcpServer = fastCSharp.code.cSharp.tcpServer.GetConfig("memoryDatabasePhysical", typeof(fastCSharp.memoryDatabase.physicalServer)); tcpServer.Host = "127.0.0.1"; tcpServer.Port = 12345; //tcpServer.SendBufferSize = 128 << 10; //tcpServer.ShareMemorySize = 128; //tcpServer.IsOnlyShareMemoryClient = true; using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer)) { if (server.Start()) { using (fastCSharp.memoryDatabase.physicalServer.tcpClient client = new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer)) { Console.WriteLine("开始加载数据..."); Stopwatch time = new Stopwatch(); time.Start(); using (table = new memoryDatabaseModelTable <identity> .remote(client, cache = new identityArray <identity>())) { cache.WaitLoad(); time.Stop(); if (table.IsDisposed) { Console.WriteLine("数据加载失败"); } else { Console.WriteLine("数据加载完成[" + cache.Count.toString() + "] " + time.ElapsedMilliseconds.toString() + "ms"); Stopwatch allTime = new Stopwatch(); using (fastCSharp.threading.task task = new threading.task(threadCount, true, fastCSharp.threading.threadPool.TinyPool)) { allTime.Start(); for (int loop = 1; loop <= 10; ++loop)//循环测试10次 { int length = 0; time.Restart(); if (isCallback) { fastCSharp.threading.waitCount waitCount = new threading.waitCount(threadCount); for (int threadIndex = 0; threadIndex != threadCount; ++threadIndex) { new insertCallback(waitCount, countPerLoop / threadCount).Insert(); } waitCount.Wait(); } else { if (threadCount == 1) { identity.task(); } else { for (int threadIndex = 0; threadIndex != threadCount; ++threadIndex) { task.Add(identity.task); } task.WaitFree(); } } table.Flush(false); time.Stop(); Console.WriteLine(((loop * countPerLoop) / 10000).toString() + "W[" + length.toString() + "] Thread[" + threadCount.toString() + "] Callback[" + isCallback.ToString() + "] " + time.ElapsedMilliseconds.toString() + "ms"); } allTime.Stop(); } Console.WriteLine(cache.Count.toString() + " " + allTime.ElapsedMilliseconds.toString() + "ms"); Console.WriteLine("测试完毕."); GC.Collect(); } } } } else { Console.WriteLine("数据库服务端启动失败."); } } Console.ReadKey(); }
internal static bool TestCase() { using (memoryDatabaseModelTable <identity> table = new memoryDatabaseModelTable <identity>(cache = new identityArray <identity>(), memoryDatabaseTable.serializeType.Index, "localIdentity")) { updateMember = table.CreateMemberMap().Append(value => value.Int); cache.WaitLoad(); if (cache.Count == 0) { identity int1 = table.Insert(new identity { Int = 1, String = "A大A" }, false); identity intOld2 = new identity { Int = 2 }; identity int2 = table.Insert(intOld2); identity int4 = table.Insert(new identity { Int = 4 }); if (int1 == null) { return(false); } if (int2 == null) { return(false); } if (int4 == null) { return(false); } intOld2.Int = 3; identity int3 = table.Update(intOld2, updateMember); if (int3 == null) { return(false); } identity delete = table.Delete(int4.Id); if (delete == null) { return(false); } return(check(table, false)); } return(check(table, true)); } }