go - Benchmark 给出命令执行超时

标签 go aerospike

我尝试使用 go 在 redis 和 aerospike 之间进行小型性能/实现比较,但我的 aerospike 代码出现“命令执行超时”。一段时间后出错。

我根据该站点安装了 aerospike 服务器,go 客户端提供的基准测试没有错误,所以我的代码可能做错了什么?

我用

运行测试
-bench="1AerospikeCounter" -benchtime 30s -cpu=1 -parallel=1

如果我启用日志记录,这就是输出, panic 发生在 PutObject 之后的错误检查中。

2015/05/14 10:20:55 Connection to address `127.0.0.1:3000` failed to establish with error: dial tcp 127.0.0.1:3000: cannot assign requested address
2015/05/14 10:20:55 Node BB9DC1A8E565000 127.0.0.1:3000: dial tcp 127.0.0.1:3000: cannot assign requested address
panic: command execution timed out.

goroutine 20 [running]:
backend/gateway/core/database.UpdateWithDelta(0xc218aeea20, 0x60c7c, 0x3fde23dba43075e1, 0xc221f181d0, 0x0, 0x0)
    /root/go/src/backend/gateway/core/database/database_test.go:247 +0x294

我的代码看起来像

type Counter struct {
    Id  int
    Pop float64
}

func Benchmark2AerospikeCounter(b *testing.B) {
    logger.Logger.SetLevel(logger.INFO)
    clientPolicy := aerospike.NewClientPolicy()
    asclient, err := aerospike.NewClientWithPolicy(clientPolicy, "127.0.0.1", 3000)
    if err != nil {
        b.Fatal(err)
    }
    b.ResetTimer()

    b.RunParallel(func(pb *testing.PB) {
        for pb.Next() {
            x := rand.Intn(1000000)
            y := rand.Float64()
            delta := Counter{Id: x, Pop: y}
            _, err := UpdateWithDelta(asclient, delta)
            if err != nil {
                b.Fatal(err)
            }
        }
    })
}

func UpdateWithDelta(client *aerospike.Client, delta Counter) (*Counter, error) {
    key, err := aerospike.NewKey("test", "counters", delta.Id)
    oldCounter := &Counter{}
    err = client.GetObject(client.DefaultPolicy, key, oldCounter)
    if v, ok := err.(types.AerospikeError); ok {
        if v.ResultCode() != types.KEY_NOT_FOUND_ERROR {
            return nil, err
        }
    } else if err != nil {
        return nil, err
    }

    newCounter := &Counter{
        Id:  delta.Id,
        Pop: oldCounter.Pop + delta.Pop,
    }

    err = client.PutObject(client.DefaultWritePolicy, key, newCounter)
    if err != nil {
        panic(err)
    }

    return newCounter, err
}

我在虚拟化的 CentOS 机器上运行它,我按照基本的 aerospike 安装说明进行操作,然后才启动它。请注意,如果我将数据库放在单独的机器上,我会得到同样的错误。

附言。如果来自 aerospike 的人正在阅读:似乎无法在您的论坛上注册谷歌。

最佳答案

这是 Go 客户端上的一个细微错误,它不会让连接在非关键错误(如 KEY_NOT_FOUND_ERROR)上返回到连接池。

您的代码现在可以工作了。

附言。我不在 stackoverflow 上,很抱歉回复晚了。

关于go - Benchmark 给出命令执行超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30212334/

相关文章:

java - 即使 "set"名称为空,Aerospike Java 客户端也会存储数据

java - 使用 Aerospike bin 名称的最佳做法是什么?

aerospike - 收到错误错误代码-1 : java. io.IOException:未知的解包类型:196

java - Aerospike 插入 1000 万个键值所需的时间太长

python - 最初是在 Python 中创建的,如何在 Go 中使用数据存储 GAE?

google-app-engine - 解析go.mod时出错,如何在具有Cloud build的App Engine上部署go app?

go - 将返回错误分配给下划线

go - 适合 geojson 解码的结构类型

go - 如何在beego中获取controller之外的cookie和session

go - 如何在 Go 中反序列化 Aerospike 记录?