dongyiyu882684 2014-05-01 20:47
浏览 59
已采纳

了解AppEngine的Go运行时上的“运行时mcycles”和“ cpu_ms”记帐

I have a Go/AppEngine app that I'm trying to fine-tune to optimize concurrent requests, which is currently cpu-bound. In the process of doing so, I'm seeing what look like anomalous values for cpu_ms in the logs, and average runtime mcycles in the dashboard.

I have a few different endpoints whose cpu use seems completely at odds with reality, but one in particular stands out. It's a simple handler that reads roughly as follows:

    func ThangHandler(w http.ResponseWriter, r *http.Request) {
        ctx := appengine.NewContext(r)

        var orgId string
        cookie, err := r.Cookie(orgCookieKey)
        if err != nil || cookie.Value == "" {
            // Check URL params as a fallback.
            r.ParseForm()
            orgId = r.Form.Get("orgId")
            if orgId == "" {
                util.HttpError(ctx, w, http.StatusForbidden)
                return
            }
        } else {
            orgId = cookie.Value
        }

        w.Header().Set("Content-Type", "application/json; charset=utf-8")
        fmt.Fprintf(w, simpleTemplate, orgId, r.Host, "true", host)
    }

The details of this code don't matter so much as the fact that it doesn't do much more than read a cookie/param and run a Printf on a very simple template string (maybe 100 characters or so).

As I write this, the AppEngine dashboard is reporting this endpoint as consuming 83 runtime mcycles average over the last hour, which seems surprisingly high. When I look at the top 20 log entries associated with these requests, I see an even stranger picture. Most of them are either ms=13 cpu_ms=0 or ms=13 cpu_ms=21 (I assume there's some quantization going on there). But about 10% are really odd, such as ms=148 cpu_ms=238!

So my actual question is this:

  • How can an endpoint this simple possibly consume 83 average mcycles, and have such high variance?
    • Should I suspect GC pauses?
  • How is it ever possible that cpu_ms > ms in the logs?
  • 写回答

1条回答 默认 最新

  • dsm0688 2014-05-08 18:03
    关注

    For the benefit of anyone that comes across this question in the future, here is the answer given by dsymonds on the google-appengine-go mailing list:

    The cpu_ms and related accounting measures are legacy holdovers from the old billing structure, which was based at least partly on CPU consumption. Nowadays it is meaningless from that perspective, and I wouldn't be surprised if those numbers are somewhat nonsensical.

    There's nothing in the Go runtime done to attribute CPU time to separate requests, nor is it really tractable to do so in a concurrent runtime. The attributing is statistical in nature, which may account for the weirdness you are seeing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误