2012-04-15 48 views
0
func init() { 
    http.HandleFunc("/", handler) 
} 

在處理函數中,代碼遍歷數據列表,處理數據並聚合結果。前往AppEngine重複部分執行http.handler

比方說,對於給定的查詢,有100個項目需要處理。對於我寫日誌到Appengine控制檯的每個項目,「項目n已處理」。

這裏是問題:

該請求不會返回。前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(0xf84, 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 
} 

UPDATE 2 切換到代碼運行如預期的F4實例之後。我仍然認爲Appengine Go的運行時間由於某種原因(內存)而失敗,並重新啓動處理程序執行。這是我最好的猜測,我不知道。

+0

可能出現您的處理程序中的Go代碼效率不高的情況。如果您發佈了這些代碼,那麼在這裏有一羣認真的Go專家,他們可能會使其更快,更有效地利用內存。 – 2012-04-16 15:03:22

+0

您可以從管理控制檯粘貼完整的請求日誌嗎? – proppy 2012-04-23 15:48:32

回答