我尝试使用go进行redis和aerospike之间的小型性能/实现比较,但是我的空中符号代码执行时间超时。"命令执行超时。"一段时间后出错。
我根据网站安装了aerospike服务器,并且go客户端提供的基准测试工作没有错误,所以我的代码可能做错了吗?
我用
运行测试-bench="1AerospikeCounter" -benchtime 30s -cpu=1 -parallel=1
如果我启用日志记录这是输出,则在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安装说明进行操作,然后启动它。请注意,如果我将数据库放在一台单独的计算机上,我会收到同样的错误。
PS。如果来自aerospike的人正在阅读:似乎无法在您的论坛上使用谷歌进行注册。
答案 0 :(得分:1)
这是Go客户端上的一个微妙错误,它不会让连接回到KEY_NOT_FOUND_ERROR等非关键错误的连接池。
您的代码现在正常运作。
PS。我不是在stackoverflow,抱歉迟到的回复。