Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRPop 在同一个进程中只能链接30-50个?【已解决 线程池的问题】 #29

Closed
OAngs opened this issue Sep 20, 2018 · 7 comments

Comments

@OAngs
Copy link

OAngs commented Sep 20, 2018

阿里云的 redis 服务。
写了一个测试应用,BRPop 超时时间 60秒,100个线程,全部阻塞结束后需要 135-144秒。
多个实例也是如此。

同一个机器多开测试应用仍然是 135-144秒完成,也就是说,每个进程都可以同时并发 30-50个 BRPop 链接。
多个客户机同时测试结果也是如此。

请问大佬,这个限制是如何产生的?有没有办法规避?

@2881099
Copy link
Owner

2881099 commented Sep 20, 2018

for (var a = 0; a < 100; a++) {
	new Thread((aa) => {
		DateTime dt = DateTime.Now;
		var ret = RedisHelper.BLPop(60, "cccc" + aa);
		Console.WriteLine($"cccc{aa}: {ret}, {DateTime.Now.Subtract(dt).TotalMilliseconds}ms");
	}).Start(a);
}
Console.ReadKey();

测试结果正常:

cccc34: , 60129.7488ms
cccc20: , 60282.6324ms
cccc15: , 60335.1473ms
cccc14: , 60335.0859ms
cccc16: , 60326.1788ms
cccc17: , 60301.9166ms
cccc18: , 60289.7199ms
cccc19: , 60289.7423ms
cccc21: , 60273.8179ms
cccc22: , 60257.1674ms
cccc23: , 60248.0073ms
cccc24: , 60239.0745ms
cccc25: , 60228.9134ms
cccc26: , 60216.8416ms
cccc27: , 60210.9641ms
cccc28: , 60203.6344ms
cccc29: , 60191.8092ms
cccc30: , 60184.3046ms
cccc31: , 60177.5059ms
cccc32: , 60163.2017ms
cccc33: , 60153.0093ms
cccc35: , 60129.7485ms
cccc36: , 60122.2616ms
cccc13: , 60352.7668ms
cccc2: , 60539.9713ms
cccc4: , 60531.7854ms
cccc0: , 60557.5156ms
cccc1: , 60550.9153ms
cccc5: , 60522.4098ms
cccc11: , 60470.0393ms
cccc12: , 60462.799ms
cccc8: , 60498.8855ms
cccc3: , 60540.6942ms
cccc6: , 60515.9879ms
cccc7: , 60507.2409ms
cccc9: , 60489.9842ms
cccc10: , 60479.6885ms
cccc46: , 60128.6588ms
cccc45: , 60236.9483ms
cccc44: , 60244.2482ms
cccc40: , 60279.8009ms
cccc41: , 60259.9397ms
cccc42: , 60266.8821ms
cccc43: , 60253.6088ms
cccc37: , 60316.0835ms
cccc38: , 60297.0225ms
cccc39: , 60289.2183ms
cccc47: , 60924.7266ms
cccc93: , 60526.5874ms
cccc90: , 60552.09ms
cccc65: , 60765.7138ms
cccc66: , 60757.7936ms
cccc67: , 60749.3567ms
cccc68: , 60742.7882ms
cccc69: , 60735.983ms
cccc70: , 60727.3415ms
cccc82: , 60619.2249ms
cccc83: , 60604.451ms
cccc84: , 60611.9539ms
cccc85: , 60596.2703ms
cccc86: , 60588.0602ms
cccc87: , 60577.9449ms
cccc88: , 60569.3207ms
cccc89: , 60559.8818ms
cccc91: , 60543.1257ms
cccc92: , 60535.9524ms
cccc64: , 60874.5851ms
cccc63: , 60882.7591ms
cccc61: , 60892.3725ms
cccc62: , 60892.2739ms
cccc50: , 61003.6861ms
cccc51: , 60996.2703ms
cccc52: , 60988.0551ms
cccc53: , 60981.5574ms
cccc54: , 60972.8298ms
cccc55: , 60940.6636ms
cccc56: , 60949.6829ms
cccc57: , 60932.8343ms
cccc58: , 60924.1674ms
cccc59: , 60914.407ms
cccc60: , 60905.3913ms
cccc94: , 60611.2432ms
cccc95: , 60603.2615ms
cccc96: , 60595.8702ms
cccc97: , 60585.8436ms
cccc98: , 60576.7594ms
cccc99: , 60568.9816ms
cccc81: , 60827.6116ms
cccc74: , 60897.9349ms
cccc75: , 60890.7292ms
cccc76: , 60871.6177ms
cccc48: , 61118.435ms
cccc49: , 61109.577ms
cccc71: , 60920.7148ms
cccc72: , 60914.4741ms
cccc73: , 60906.5017ms
cccc77: , 60862.5874ms
cccc78: , 60854.6326ms
cccc79: , 60842.3964ms
cccc80: , 60834.7236ms

@2881099
Copy link
Owner

2881099 commented Sep 20, 2018

使用 BRPop 也是同样结果。

@2881099
Copy link
Owner

2881099 commented Sep 20, 2018

BRPopAsync 貌似会延长时间,你是不是用异步方法。

@2881099
Copy link
Owner

2881099 commented Sep 20, 2018

测试了多次,BRPopAsync 异步方法,线程数太少处理不过来

需要设置 ThreadPool.SetMinThreads(1000, 1000);,设置后测试 BRPopAsync 平均阻塞62秒。

不然延时会比较严重,同步方法没有影响。

@OAngs
Copy link
Author

OAngs commented Sep 21, 2018

测试了多次,BRPopAsync 异步方法,线程数太少处理不过来

需要设置 ThreadPool.SetMinThreads(1000, 1000);,设置后测试 BRPopAsync 平均阻塞62秒。

不然延时会比较严重,同步方法没有影响。

收到,谢了~ 经测试,您这个 Thread 没问题,我用的是 Task.Run() ... 应该是 Task.Run() 的问题!万分感谢!

@2881099
Copy link
Owner

2881099 commented Sep 21, 2018

Task 依赖 ThreadPool 线程池执行,原作者不支持异步阻塞 BRPopAsync 方法,估计也是考虑这个缺陷。

@OAngs
Copy link
Author

OAngs commented Sep 21, 2018

使用 Task.Run 的话设置 线程池最大和最小线程后问题解决。
System.Threading.ThreadPool.SetMaxThreads
System.Threading.ThreadPool.SetMinThreads

@OAngs OAngs changed the title BRPop 在同一个进程中只能链接30-50个? BRPop 在同一个进程中只能链接30-50个?【已解决 线程池的问题】 Sep 21, 2018
@OAngs OAngs closed this as completed Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants