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