使用缓冲流BufferedStream包装网络流,加速响应数据读取分析。压测峰值315万每秒,批删除

This commit is contained in:
智能大石头 2025-01-10 01:33:42 +08:00
parent 3129b84dc6
commit 9c55d4e250
1 changed files with 4 additions and 2 deletions

View File

@ -309,12 +309,14 @@ public class RedisClient : DisposeBase
/// <returns></returns> /// <returns></returns>
protected virtual IList<Object?> GetResponse(Stream ns, Int32 count) protected virtual IList<Object?> GetResponse(Stream ns, Int32 count)
{ {
var ms = new BufferedStream(ns);
Char header; Char header;
var buf = Pool.Shared.Rent(1); var buf = Pool.Shared.Rent(1);
try try
{ {
// 取巧进行异步操作,只要异步读取到第一个字节,后续同步读取 // 取巧进行异步操作,只要异步读取到第一个字节,后续同步读取
var n = ns.Read(buf, 0, 1); var n = ms.Read(buf, 0, 1);
if (n <= 0) return []; if (n <= 0) return [];
header = (Char)buf[0]; header = (Char)buf[0];
@ -324,7 +326,7 @@ public class RedisClient : DisposeBase
Pool.Shared.Return(buf); Pool.Shared.Return(buf);
} }
return ParseResponse(ns, count, header); return ParseResponse(ms, count, header);
} }
/// <summary>异步接收响应</summary> /// <summary>异步接收响应</summary>