Pre-application latency with AppEngine

31 views
Skip to first unread message

Prateek Malhotra

unread,
Nov 20, 2019, 10:06:54 AM11/20/19
to google-appengine-go
I've tested this on both Go 1.12 and Go 1.13: I added tracing to my application and noticed a lag between when AppEngine reports receiving the request and when my application registers receiving the request. In order to eliminate any of my middlewares/setup process as the culprit, I made a barebones handler to test the latency (code found below) and notice anywhere between a ~30-90ms lag time from when AppEngine starts the trace until my application registers the request. This is after I let it "warm" up first with 10 requests.


in Go 1.12:
Browser TTFB: 112.69ms
StackDriver Trace Output:
@0 ms (HTTP load balancer )
Traced time 62.974 ms
Untraced time 46.026 ms
@18.913 ms (AppEngine Entry)
Traced time 0.073 ms
Untraced time 62.901 ms
@50.164 ms (My Application)

in Go 1.13:
Browser TTFB: 62.19ms
StackDriver Trace Output:
@0 ms (HTTP load balancer )
Traced time 21.039 ms
Untraced time 41.961 ms
@18.053 ms (AppEngine Entry)
Traced time 0.066 ms
Untraced time 20.973 ms
@38.181 ms (My Application)


This feels higher than it should but I was curious if this is expected?


app.yaml:
runtime: go112 # or go113
service: latency


go.mod:
module main

go 1.12

require (
)

main.go:
package main

import (
"context"
"fmt"
"log"
"net/http"
"os"

)

func main() {
ctx := context.Background()

exp, err := stackdriver.NewExporter(stackdriver.Options{
Context:   ctx,
ProjectID: os.Getenv("GOOGLE_CLOUD_PROJECT"),
})

if err != nil {
panic(err)
}

trace.RegisterExporter(exp)
http.HandleFunc("/", indexHandler)

h := TraceHandler(http.DefaultServeMux)

port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}

log.Printf("Listening on port %s", port)

if err := http.ListenAndServe(":"+port, h); err != nil {
log.Fatal(err)
}
}

// TraceHandler sets up OpenCensus middleware for tracing and stats
func TraceHandler(h http.Handler) http.Handler {
return &ochttp.Handler{
Handler:          h,
Propagation:      &propagation.HTTPFormat{},
IsPublicEndpoint: false,
}
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}

fmt.Fprint(w, "Hello, World!")
}

Thank you,
Prateek

Reply all
Reply to author
Forward
0 new messages