func init() {
http.HandleFunc("/", handler)
}
在处理程序函数中,有代码遍历数据列表、处理它并聚合结果。
假设对于给定的查询,有 100 个项目需要处理。对于我向 Appengine 控制台写入日志的每个项目,“Item n has been processed”。
问题是:
请求没有返回。前 40 条左右的日志消息,然后重复,再重复。它总是停止相同的项目,然后重新启动。
我最好的猜测是应用程序达到了内存限制或其他原因,而 Appengine Go 运行时只是重新启动并重新执行处理程序。
对于一小部分项目,处理按预期进行,并且日志没有显示任何循环。
请求日志中没有错误,但另一个日志显示:
panic: poll_ctl
goroutine 3 [running]:
runtime/eventloop.(*pollServer).ctlfd(0x9035f8, 0x204100000005, 0x3, 0x2041, 0x0, ...)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:428 +0xdf
runtime/eventloop.(*pollServer).loop(0x9035f8, 0x0)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:411 +0x4d8
created by runtime/eventloop.init·1
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:232 +0x40
goroutine 1 [select (no cases)]:
appengine_internal/fd_transport.serveHTTP(0x7fff76502f58, 0x70615f2f00000002, 0x7fff76502f5b, 0x3, 0x7fff76502f6c, ...)
go/src/pkg/appengine_internal/fd_transport/fd_transport.go:44 +0x26b
appengine_internal.Main()
go/src/pkg/appengine_internal/internal.go:184 +0x1a8
main.main()
_go_main.go:16 +0x18
goroutine 2 [select]:
created by _
_.go:568 +0xd2
goroutine 10 [chan receive]:
runtime/eventloop.(*pollServer).wait(0x9035f8, 0xf840095a60, 0xf84011ac30, 0xb, 0x1, ...)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:472 +0x1a7
runtime/eventloop.(*FD).ReadFrom(0xf840095a50, 0xf840138000, 0x7d0000007d0, 0xf800000000, 0x0, ...)
go/src/pkg/runtime/eventloop/fd.go:135 +0x1c2
created by _
_.go:144 +0x7a
goroutine 5 [chan receive]:
created by _
_.go:461 +0x3ca
goroutine 6 [semacquire]:
sync.runtime_Semacquire(0xf8408034d8, 0xf8408034d8)
go/src/pkg/runtime/zsema_amd64.c:146 +0x25
sync.(*Cond).Wait(0xf840096bb0, 0x1)
go/src/pkg/sync/cond.go:67 +0xaa
created by _
_.go:462 +0x3e1
goroutine 7 [chan receive]:
runtime/eventloop.(*pollServer).wait(0x9035f8, 0xf840095c70, 0xf84011ac30, 0xb, 0x1, ...)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:472 +0x1a7
runtime/eventloop.(*FD).Read(0xf840095c60, 0xf84113a000, 0x972a80000000c, 0x2b5800000000, 0xf84011ac30, ...)
go/src/pkg/runtime/eventloop/fd.go:93 +0x18c
io.ReadAtLeast(0xf84012c0c0, 0xf840095c60, 0xf84113a000, 0x972a80000000c, 0x2b580000000c, ...)
go/src/pkg/io/io.go:254 +0xc3
io.ReadFull(0xf84012c0c0, 0xf840095c60, 0xf84113a000, 0x972a80000000c, 0xf840095c60, ...)
go/src/pkg/io/io.go:273 +0x69
created by _
_.go:845 +0x2c6
goroutine 11 [runnable]:
runtime/eventloop.(*pollServer).wait(0x9035f8, 0xf840095b10, 0xf84011ac30, 0xb, 0x1, ...)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:472 +0x1a7
runtime/eventloop.(*FD).Accept(0xf840095b00, 0x0, 0x0, 0xf84011ac30, 0xb, ...)
go/src/pkg/runtime/eventloop/fd.go:72 +0x185
net/http.(*Server).Serve(0xf840129f00, 0xf8400cfa80, 0xf840095b00, 0x0, 0x0, ...)
go/src/pkg/net/http/server.go:1012 +0x88
net/http.Serve(0xf8400cfa80, 0xf840095b00, 0xf84012c090, 0xf8400e0b10, 0xf8400e0b10, ...)
go/src/pkg/net/http/server.go:977 +0x71
created by _
_.go:145 +0xe9
goroutine 12 [timer goroutine (idle)]:
created by addtimer
go/src/pkg/runtime/ztime_amd64.c:70
goroutine 13 [runnable]:
runtime/eventloop.(*pollServer).wait(0x9035f8, 0xf8400959b0, 0xf84011ac30, 0xb, 0x1, ...)
go/src/pkg/runtime/eventloop/poll_linux_amd64.go:472 +0x1a7
runtime/eventloop.(*FD).Read(0xf8400959a0, 0xf840139000, 0x100000001000, 0x0, 0xf84011ac30, ...)
go/src/pkg/runtime/eventloop/fd.go:93 +0x18c
io.(*LimitedReader).Read(0xf840123580, 0xf840139000, 0x100000001000, 0xf8900000000, 0x0, ...)
go/src/pkg/io/io.go:394 +0xc1
bufio.(*Reader).fill(0xf840129f80, 0x2b5853e92000)
go/src/pkg/bufio/bufio.go:77 +0xf0
bufio.(*Reader).Read(0xf840129f80, 0xf84013d000, 0x27100000000c, 0xc, 0x0, ...)
go/src/pkg/bufio/bufio.go:142 +0x188
io.ReadAtLeast(0xf84012c600, 0xf84012c570, 0xf84013d000, 0x27100000000c, 0xc, ...)
go/src/pkg/io/io.go:254 +0xc3
io.ReadFull(0xf84012c600, 0xf84012c570, 0xf84013d000, 0x27100000000c, 0xf84012c570, ...)
go/src/pkg/io/io.go:273 +0x69
net/http.(*conn).serve(0xf8401320c0, 0x0)
go/src/pkg/net/http/server.go:656 +0x621
created by net/http.(*Server).Serve
go/src/pkg/net/http/server.go:1040 +0x430
goroutine 59 [sleep]:
time.Sleep(0x5dfdee1, 0xf8408034d0)
go/src/pkg/runtime/ztime_amd64.c:22 +0x49
created by _
_.go:791 +0xc4
goroutine 15 [chan receive]:
也许我没有记录所有错误,但即使如此,什么会导致循环?
更新 近乎无休止的循环很快耗尽了我的数据存储写入配额,现在我收到了一个无引号错误,正在记录。错误记录后,再次调用处理程序。又一次……
func handleError(w http.ResponseWriter, c appengine.Context, err error) {
c.Infof("ERROR")
c.Errorf("ERROR datastore: %s", err.Error())
}
...
rk, err := datastore.Put(c, rk, e)
if err != nil {
handleError(w, c, err)
return
}
更新 2 切换到 f4 实例后,代码按预期运行。我仍然认为 Appengine Go 运行时由于某种原因(内存)默默地失败,并重新启动处理程序执行。这是我最好的猜测,我不知道。
最佳答案
http 请求有 30 秒超时。在您转移到更快的实例之前,流程是否需要那么长时间?您可以使用后端进程进行长期处理。 https://developers.google.com/appengine/docs/go/backends/overview
关于google-app-engine - Go AppEngine 重复部分执行 http.handler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10165376/
我在使用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
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
我遵循了教程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
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
如何检查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.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里