Benchmark给出了命令执行超时的提示。

huangapple go评论84阅读模式
英文:

Benchmark gives command execution timed out

问题

我正在尝试使用Go语言对Redis和Aerospike进行性能/实现比较,但是我的Aerospike代码在一段时间后出现了"command execution timed out."的错误。

我按照网站上的说明安装了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阅读这个问题:在你们的论坛上好像无法使用Google注册。

英文:

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.

答案1

得分: 1

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

你的代码现在可以正常工作了。

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

英文:

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.

huangapple
  • 本文由 发表于 2015年5月13日 18:36:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/30212334.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定