public void ProcessRequest(HttpContext context) { if (toplogyLoader == null) { lock (lockObject) { if (toplogyLoader == null) { string path = context.Server.MapPath(context.Request.Url.AbsolutePath); if (path.EndsWith("defaultHandle.ashx")) { path = path.Substring(0, path.Length - 18); } toplogyLoader = new TopologyLoader(path + "topology.txt", Encoding.UTF8, new TopologyParser()); rpcClient = new RpcClient(toplogyLoader, new TimeoutSettings(500)); instance = rpcClient.GetService <IProcessGoodDetail.IGoodManager>(); } } } string[] ids = new string[] { randNumber.Next(1000).ToString(), randNumber.Next(10000).ToString() }; string result = instance.GetGoodDetail(ids, randNumber.Next(100), randNumber.Next(1000), "北京"); context.Response.ContentType = "text/plain"; context.Response.Write(result); }
static void Main(string[] args) { thbyside = new Thread(Run); thbyside.IsBackground = true; thbyside.Start(); //string content = RunTestHttpData(); toplogyLoader = new TopologyLoader("../../../Topology/topology.txt", Encoding.UTF8, new TopologyParser()); rpcClient = new RpcClient(toplogyLoader, new TimeoutSettings(500)); while (true) { Stopwatch sw = new Stopwatch(); sw.Start(); instance = rpcClient.GetService <IProcessGoodDetail.IGoodManager>(); int testCount = 10000; Task[] tsks = new Task[testCount]; for (int i = 0; i < tsks.Length; i++) { tsks[i] = Task.Factory.StartNew(() => { RunTestData(); }); //tsks[i] = Task.Factory.StartNew(() => { RunTestHttpData(); }); } Task.WaitAll(tsks); //for (int i = 0; i < testCount; i++) //{ // RunTestData(); //} sw.Stop(); Console.WriteLine(string.Format("耗时:{0} ms success:{1} fail:{2}", sw.ElapsedMilliseconds, successCount, failCount)); ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) { break; } Thread.Sleep(1000); } Console.ReadKey(); }
static void Main(string[] args) { var topologyLoader = new TopologyLoader("../../../Topology/topology.txt", Encoding.UTF8, new TopologyParser()); var settingsLoader = new SettingsLoader("../../../Settings/Host.txt", Encoding.UTF8, new HostSettingsParser()); var kernel = new RpcClientServer(topologyLoader, new TimeoutSettings(5000), settingsLoader); kernel.StartHost(); string line = Console.ReadLine(); while (line != "exit") { line = Console.ReadLine(); } kernel.StopHost(); }
static void Main(string[] args) { var topologyLoader = new TopologyLoader("../Topology/topology.txt", Encoding.UTF8, new TopologyParser()); var client = new RpcClient(topologyLoader, new TimeoutSettings(5000)); var myService = client.GetService <IMyService>(); string line; while ((line = Console.ReadLine()) != "exit") { switch (line) { case "greet": { Console.Write("Enter a name: "); var name = Console.ReadLine(); var greeting = myService.Greet(name); Console.WriteLine(greeting); } break; case "add": { Console.Write("Enter a: "); var a = int.Parse(Console.ReadLine()); Console.Write("Enter b: "); var b = int.Parse(Console.ReadLine()); var sum = myService.Add(a, b); Console.WriteLine(sum); } break; default: { Console.WriteLine("Unkown command"); } break; } } }
static void Main(string[] args) { var topologyLoader = new TopologyLoader("../Topology/topology.txt", Encoding.UTF8, new TopologyParser()); var client = new RpcClient(topologyLoader, new TimeoutSettings(1, 100)); var myService = client.GetService <IMyService>(); var clientLog = new FileLogger("clientlog.txt"); string line; while ((line = Console.ReadLine()) != "exit") { switch (line) { case "void": { myService.Void(); Console.WriteLine("Void Complete"); break; } case "greet": { Console.Write("Enter a name: "); var name = Console.ReadLine(); var greeting = myService.Greet(name); Console.WriteLine(greeting); break; } case "add": { Console.Write("Enter a: "); var a = int.Parse(Console.ReadLine()); Console.Write("Enter b: "); var b = int.Parse(Console.ReadLine()); var sum = myService.Add(a, b); Console.WriteLine(sum); break; } case "aadd": { Console.Write("Enter a: "); var a = int.Parse(Console.ReadLine()); Console.Write("Enter b: "); var b = int.Parse(Console.ReadLine()); var sum = myService.AddAsync(a, b).Result; Console.WriteLine(sum); break; } case "throw": { try { myService.Throw(); } catch (Exception ex) { Console.WriteLine(ex); } break; } case "sleep": { try { myService.SleepOneSecond(); } catch (Exception ex) { Console.WriteLine(ex); } break; } case "stress": { var globalStart = DateTime.Now; for (int i = 0; i < 10000; i++) { int iLoc = i; var start = DateTime.Now; clientLog.Info(string.Format("{0}:\t{1} start", iLoc, DateTime.Now - globalStart)); myService.AddAsync(i, 2 * i).ContinueWith(t => clientLog.Info(string.Format("{0}:\t{1}\t{2}", iLoc, DateTime.Now - globalStart, DateTime.Now - start))); } break; } default: { Console.WriteLine("Unkown command"); break; } } } }