performance - 执行redis操作的Go代码中缺少毫秒

标签 performance go redis

下面是从 Redis 获取值(value)的示例片段。我正在通过管道传输 3 个 redis 命令并获取值。这里的问题是“缺少毫秒”。 Redis 管道花费的时间明显更短(小于 5 毫秒),但执行 Get 操作花费的总时间超过 10 毫秒。不确定哪个操作需要时间,解码不是问题,因为我测量了 len(bytes) 和时间。任何帮助深表感谢。

请求/秒 = 300,在 3 个 AWS 大型实例上运行,具有强大的 25GB redis 实例。使用 10 个默认连接。

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

最佳答案

执行一条redis命令的时间包括:

  1. 应用服务器预处理
  2. 应用服务器和redis服务器之间的往返时间
  3. Redis 服务器处理时间

在正常操作中,(2) 花费的时间最多。

关于performance - 执行redis操作的Go代码中缺少毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50323873/

相关文章:

image - 更改单个像素的颜色 - Golang 图像

go - 当字段实现 UnmarshalJSON 时,Unmarshal 嵌入式字段指针会出现困惑

arrays - 将函数的返回值分配给Golang中Struct数组中的元素

node.js - Laravel 5 - Homestead - Redis - NodeJs - Socket IO 运行不正常

jquery - 查找嵌套表格单元格内容 - jquery 查询性能

mysql - 表级锁定保证什么?

php - 如何命名异常(PHP)?

redis - Redis 在 Windows 上稳定吗?

c# - 更新操作缓存并保持不同步

python - 将除法替换为零 numpy