Performance 执行redis操作的Go代码中缺少毫秒
下面是从Redis获取值的示例代码段。我正在通过管道传输3个redis命令并获取值。这里的问题是“缺少毫秒”。redis管道所花费的时间明显较低(小于5ms),但执行Get操作所花费的总时间超过10ms。不确定哪个操作需要时间,解组不是问题,因为我测量了len(字节)和计时。非常感谢您的帮助 Request/Second=300,在3个AWS大型实例上运行,具有强大的25GB redis实例。使用10个默认连接Performance 执行redis操作的Go代码中缺少毫秒,performance,go,redis,Performance,Go,Redis,下面是从Redis获取值的示例代码段。我正在通过管道传输3个redis命令并获取值。这里的问题是“缺少毫秒”。redis管道所花费的时间明显较低(小于5ms),但执行Get操作所花费的总时间超过10ms。不确定哪个操作需要时间,解组不是问题,因为我测量了len(字节)和计时。非常感谢您的帮助 Request/Second=300,在3个AWS大型实例上运行,具有强大的25GB redis实例。使用10个默认连接 func Get(params...) <-chan CacheResult
func Get(params...) <-chan CacheResult {
start := time.Now()
var res CacheResult
defer func() {
resCh <- res
}()
type timers struct {
total time.Duration
pipeline time.Duration
unmarshal time.Duration
}
t := timers{}
startPipeTime := time.Now()
// pipe line commands
pipe := c.client.Pipeline()
// 3 commands pipelined (HGET, HEGT, GET)
if _, res.Err = pipe.Exec(); res.Err != nil && res.Err != redis.Nil {
return resCh
}
sinceStartPipeTime := time.Since(startPipeTime)
// get query values like below for HGET & GET
if val, res.Err = cachedValue.Bytes(); res.Err != nil {
return resCh
}
// Unmarshal the query value
startUnmarshalTime := time.Now()
var cv common.CacheValue
if res.Err = json.Unmarshal(val, &cv); res.Err != nil {
return resCh
}
sinceStartUnmarshalTime := time.Since(startUnmarshalTime)
t.unmarshal = sinceStartUnmarshalTime
endTime := time.Since(start)
xlog.Infof("Timings total:%s, "+
"pipeline(redis):%s, unmarshaling(%vB):%s", t.total, t.pipeline, len(val), t.unmarshal)
return resCh
func Get(params…执行redis命令的时间包括:
应用服务器预处理
app server和redis server之间的往返时间
Redis服务器处理时间
在正常操作中,(2)需要最长的时间。Redis不是问题所在。上面代码中的其他内容需要3到5毫秒甚至更长时间。你读过第(2)部分了吗?这是应用服务器和redis之间的往返时间。这通常需要最长的时间,并且因网络条件而异。感谢您的回复。但是这段时间不是在“time.Since(startPipeTime)”中计算的吗?你在使用哪个redis客户端?我想你是在异步调用管道Lyso,那么计时的输出是什么?