我尝试使用 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/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否
//1.验证返回状态码是否是200pm.test("Statuscodeis200",function(){pm.response.to.have.status(200);});//2.验证返回body内是否含有某个值pm.test("Bodymatchesstring",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");});//3.验证某个返回值是否是100pm.test("Yourtestname",function(){varjsonData=pm.response.json
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
使用rails4,ruby2。我在rails配置中为我的cookiesession设置了30分钟的超时时间。问题是,如果我转到表单,让session超时,然后提交表单,我会收到此ActionController::InvalidAuthenticityToken错误。如何在Rails中优雅地处理这个错误?比如说,重定向到登录屏幕? 最佳答案 在您的ApplicationController:rescue_fromActionController::InvalidAuthenticityTokendoredirect_tosome_p
我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption