Im trying to do a small performance/implementation comparison between redis and aerospike using go, but my aerospike code get a "command execution timed out." error after a while.
I installed aerospike server according to the site, and the supplied benchmark with the go client works without error so maybe Im doing something wrong in my code?
I run the test with
-bench="1AerospikeCounter" -benchtime 30s -cpu=1 -parallel=1
If I enable logging this is the output, the panic happens at the error check after 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
My code looks like
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
}
I run it on a virtualized CentOS box, I followed the basic aerospike installation instructions and then just started it. Note that I get the same error if I put the db on a separate machine.
ps. If someone from aerospike is reading: It doesnt seems to be possible to signup with google on your forum.
This has been a subtle bug on the Go client that would not let the connections go back to the connection pool on non-critical errors like KEY_NOT_FOUND_ERROR.
Your code works now.
ps. I'm not on stackoverflow, sorry for the late reply.