private void Test() { int threadCount = 2000; int count = 0; for (int i = 0; i < threadCount; i++) { Thread thread = new Thread(() => { UserService.Iface userService = GlobalSetting.GetService <UserService.Iface>(); for (int j = 0; j < 10; j++) { UserInfo user = userService.GetUser(10); } IDisposable dispose = userService as IDisposable; dispose.Dispose(); Interlocked.Increment(ref count); }); thread.Start(); } bool timeout = false; //Timer timer = new Timer((state) => timeout = true,null,10000,-1); while (count < threadCount && !timeout) { } if (timeout) { Console.WriteLine($"超时:执行成功{count}次"); } else { Console.WriteLine($"正常结束:执行成功{count}次"); } }
public void 客户端新增一条数据() { UserService.Iface userService = GlobalSetting.GetService <UserService.Iface>(); Assert.AreEqual(true, userService.Add(new UserInfo { UserID = 10, UserName = "******", Sex = true })); IDisposable dis = userService as IDisposable; dis?.Dispose(); }
public void 客户端单个请求() { UserService.Iface userService = GlobalSetting.GetService <UserService.Iface>(); for (int j = 0; j < 1000; j++) { UserInfo user = userService.GetUser(10); Assert.IsNotNull(user); Assert.AreEqual(10, user.UserID); } IDisposable dis = userService as IDisposable; dis?.Dispose(); }
public void 使用连接池内缓存的TTransport请求_线程延时以达到最大的缓存限制() { int threadCount = 1000; int count = 0; for (int i = 0; i < threadCount; i++) { Thread thread = new Thread(() => { UserService.Iface userService = GlobalSetting.GetService <UserService.Iface>(); for (int j = 0; j < 10; j++) { UserInfo user = userService.GetUser(10); } Thread.Sleep(1000); IDisposable dispose = userService as IDisposable; dispose.Dispose(); Interlocked.Increment(ref count); }); thread.Start(); } bool timeout = false; //Timer timer = new Timer((state) => timeout = true,null,10000,-1); while (count < threadCount && !timeout) { } if (timeout) { Console.WriteLine($"超时:执行成功{count}次"); } else { Console.WriteLine($"正常结束:执行成功{count}次"); } ThriftConnectionPool pool = GlobalSetting.GetService <IThriftConnectionPool>() as ThriftConnectionPool; foreach (var item in pool.ConnectionStore.ConnectionPool) { Console.WriteLine("连接池内的TTransport:" + item.Value.Count); } }
static void Main(string[] args) { ThriftServiceContainer serviceContainer = new ThriftServiceContainer(); //serviceContainer.AddActionFilter(new TestActionFilter()); GlobalSetting.Start(serviceContainer); //UserService.Iface tmpService = GlobalSetting.GetService<UserService.Iface>(); //tmpService.Add(new UserInfo { UserID = 10, UserName = "******", Sex = true }); //UserInfo tmp123 = tmpService.GetUser(10); //Console.WriteLine(JsonConvert.SerializeObject(tmp123)); //return; //container.Reaplce(typeof(IThriftConnectionPool),new FreshConnectionPool()); //container.AddActionFilter(new TestActionFilter()); //SelfServiceAssembliesResolver resolver = new SelfServiceAssembliesResolver(); //container.Reaplce(typeof(IServiceAssembliesResolver), resolver); int threadCount = 2000; int count = 0; Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < threadCount; i++) { Thread thread = new Thread(() => { IDisposable dis = null; try { UserService.Iface userService = GlobalSetting.GetService <UserService.Iface>(); for (int j = 0; j < 10; j++) { UserInfo user = userService.GetUser(10); } dis = userService as IDisposable; Console.WriteLine("OK"); } catch (Exception err) { Console.WriteLine(err.Message); } finally { dis?.Dispose(); Interlocked.Increment(ref count); } }); thread.Start(); } bool timeout = false; //Timer timer = new Timer((state) => timeout = true,null,10000,-1); while (count < threadCount && !timeout) { } if (timeout) { Console.WriteLine($"超时:执行成功{count}次"); } else { Console.WriteLine($"正常结束:执行成功{count}次"); } watch.Stop(); Console.WriteLine("耗时" + watch.ElapsedMilliseconds); ThriftConnectionPool pool = GlobalSetting.GetService <IThriftConnectionPool>() as ThriftConnectionPool; if (pool == null) { return; } foreach (var item in pool.ConnectionStore.ConnectionPool) { Console.WriteLine("连接池内的TTransport:" + item.Value.Count); int index = 0; foreach (var tmp in item.Value) { index++; Console.WriteLine(index + " " + (tmp.IsFree ? "空闲":"忙碌")); } } Thread.Sleep(9 * 1000); UserService.Iface face = GlobalSetting.GetService <UserService.Iface>(); Console.WriteLine("剩余连接:" + pool.ConnectionStore.ConnectionPool.First().Value.Count); Console.ReadKey(); }