首页 新闻 搜索 专区 学院

.net core 3.1 使用StackExchange.Redis 高并发下timeout超时问题如何解决?

0
悬赏园豆:50 [待解决问题]

StackExchange.Redis 在压测下频繁超时,按照网上的解决方案设置.ThreadPool.SetMinThreads也不起作用,请教大佬们有何解决方案;
Timeout awaiting response (outbound=0KiB, inbound=0KiB, 5981ms elapsed, timeout is 5000ms), command=HMGET, next: HMGET xxxxxxxxx:access:ccbbe50309060380bd37f96551b75ae6,
inst: 0, qu: 0, qs: 7, aw: False, rs: ReadAsync, ws: Idle, in: 4036, in-pipe: 0, out-pipe: 0, serverEndpoint: 112.12.15.12:6379,
mc: 1/1/0,
mgr: 10 of 10 available,
clientName: localhost,
IOCP: (Busy=0,Free=1000,Min=8,Max=1000),
WORKER: (Busy=58,Free=32709,Min=8,Max=32767),
v: 2.1.58.34321 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
StackExchange.Redis.RedisTimeoutException: Timeout awaiting response (outbound=0KiB, inbound=0KiB, 5981ms elapsed, timeout is 5000ms), command=HMGET, next: HMGET StarPraise.User.Service.UserAccount.Tokens.TokenProvider:TokenData:access:ccbbe50309060380bd37f96551b75ae6, inst: 0, qu: 0, qs: 7, aw: False, rs: ReadAsync, ws: Idle, in: 4036, in-pipe: 0, out-pipe: 0, serverEndpoint: 172.22.25.32:6379, mc: 1/1/0, mgr: 10 of 10 available, clientName: localhost, IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=58,Free=32709,Min=8,Max=32767), v: 2.1.58.34321 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)

< >
分享
所有回答(1)
0

需要设置一下 系统线程池的 最小线程池

        public static void Main(string[] args)
        {
            #if !DEBUG
            //为了解决redis 超时的问题,设置最小线程数量
            //https://gist.github.com/JonCole/e65411214030f0d823cb
            ThreadPool.SetMinThreads(250, 250);
            #endif
            CreateHostBuilder(args).Build().Run();
        }

gt1987 | 园豆:936 (小虾三级) | 2021-06-09 13:40

这个值怎么设置合理,怎么计算呢

支持(0) 反对(0) 狼性法则 | 园豆:91 (初学一级) | 2021-06-09 14:20

@狼性法则: 这个看你系统并发情况和服务器资源估算一下,通常设个100就好了,async await 异步编程稍微再加点。

支持(0) 反对(0) gt1987 | 园豆:936 (小虾三级) | 2021-06-09 14:53

@gt1987: 还有个问题 不知道大佬遇见过没有,httpclientfactory 在高并发的时候经常超时或者任务取消,怎么解决的?不压测1000请求平均几十毫秒,压测1000线程组,200用户组以后就到150ms了

支持(0) 反对(0) 狼性法则 | 园豆:91 (初学一级) | 2021-06-10 14:13

@狼性法则:
1 httpclientfactory 怎么用的?
2 压测什么问题?压测接口,接口里面 使用了 httpclientfactory ?

支持(1) 反对(0) gt1987 | 园豆:936 (小虾三级) | 2021-06-10 14:32

@gt1987: 直接startup 注入services.AddHttpClient();,
直接在构造方法中拿的
private readonly IHttpClientFactory _clientFactory;
public BasicUsageModel(IHttpClientFactory clientFactory)
{
_clientFactory = clientFactory;
}
官方代码
var request = new HttpRequestMessage(HttpMethod.Get,"http://www.baidu.com");
var client = _clientFactory.CreateClient();
var response = await client.SendAsync(request);

支持(0) 反对(0) 狼性法则 | 园豆:91 (初学一级) | 2021-06-10 15:03

@狼性法则: 这种写法没问题的。
压测问题就不太好说了,200个用户组压个30秒 不至于超时

支持(0) 反对(0) gt1987 | 园豆:936 (小虾三级) | 2021-06-10 16:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册