在Google Cloud Run上进行服务到服务呼叫时出现奇数延迟

时间:2019-08-22 01:59:46

标签: google-cloud-run

我在Cloud Run区域 us-central1 上部署了两个用Go编写的简单服务,当我有一个服务调用另一个服务时,我遇到了奇怪的延迟。

代码如下:

test1.go

test2.go

我按如下所述部署两项服务:

#!/bin/bash
cd "$(dirname "$0")"

deploy () {
  gcloud beta run deploy $1 \
    --image "${2}/project-x/serverless-test/${1}" \
    --platform managed \
    --allow-unauthenticated \
    --region $3 \
    --async
}

deploy "test1" "gcr.io" "us-central1"
deploy "test2" "gcr.io" "us-central1"

部署后,我将连续10次获得服务test1的呼叫服务test2

https://test1-sfh32yualq-uc.a.run.app/?url=https://test2-sfh32yualq-uc.a.run.app

哪个会产生以下输出:

{
  "message": "Hello, World! Took 2.083242593s",
  "ok": true,
  "responses": [
    "called https://test2-sfh32yualq-uc.a.run.app #1 : received 5 bytes in 209.859893ms",
    "called https://test2-sfh32yualq-uc.a.run.app #2 : received 5 bytes in 207.109789ms",
    "called https://test2-sfh32yualq-uc.a.run.app #3 : received 5 bytes in 206.209135ms",
    "called https://test2-sfh32yualq-uc.a.run.app #4 : received 5 bytes in 207.54638ms",
    "called https://test2-sfh32yualq-uc.a.run.app #5 : received 5 bytes in 208.772364ms",
    "called https://test2-sfh32yualq-uc.a.run.app #6 : received 5 bytes in 206.981902ms",
    "called https://test2-sfh32yualq-uc.a.run.app #7 : received 5 bytes in 211.108579ms",
    "called https://test2-sfh32yualq-uc.a.run.app #8 : received 5 bytes in 207.932876ms",
    "called https://test2-sfh32yualq-uc.a.run.app #9 : received 5 bytes in 208.195697ms",
    "called https://test2-sfh32yualq-uc.a.run.app #10 : received 5 bytes in 209.33479ms"
  ]
}

现在是奇数部分;

a)我希望test1调用同一地区的test2 的响应时间会更低

b)当我使用来自日本横滨(即整个太平洋地区)的Chrome 呼叫test2时,我获得了约150毫秒的平均响应时间:

calling test2 from Japan

服务test2在通过浏览器直接调用时似乎表现出预期的效果,但是在test1内部调用时表现却很慢。

Cloud Run日志似乎证实了这一点:

Could Run Logs

0 个答案:

没有答案