如何解决“此请求导致您的应用启动了新流程..."导致的应用引擎中的高延迟? [英] How solve High latency in app engine caused by "This request caused a new process to be started for your application..."?

查看:104
本文介绍了如何解决“此请求导致您的应用启动了新流程..."导致的应用引擎中的高延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与标准环境应用引擎,python 3.7和cloud sql(Mysql)一起使用的应用

检查日志,其中一些具有很高的延迟(超过4秒),而预期的时间是800毫秒.所有这些日志都伴随以下消息:

此请求导致您的应用程序开始了新的流程, 从而导致您的应用程序代码首次被加载. 因此,此请求可能比常规请求花费更长的时间并使用更多的CPU 请求您的应用程序."

我了解到,当它指的是新流程时,它指的是新实例的部署(因为我使用自动缩放),但是奇怪的是,在某些情况下,将这些日志与实例的部署进行比较时,它是匹配的,但是在其他情况则不是.

我的问题是,如何减少这些延迟?

应用程序引擎配置为:

runtime: python37
env: standard
instance_class: F1
handlers:
  - url: /static/(.*)
    static_files: static/\1
    require_matching_file: false
    upload: static/.*
  - url: /.*
    script: auto
    secure: always
  - url: .*
    script: auto
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic
network: {}

解决方案

您注意到,这些缓慢的请求会在应用引擎需要为您的应用启动新实例时发生,因为初始加载速度很慢(这些称为正在加载请求" ).

但是,App Engine确实提供了一种使用预热"请求-基本上,是对您的应用程序的虚拟请求,以便在实际需要它们时提前启动实例.这样可以减少但不能消除影响用户的加载请求.

这可能会稍微增加您的成本,但是它会减少加载请求的延迟,因为这些虚拟请求将占用启动新实例的成本.

在python 3.7运行时中,您可以在app.yamlinbound_services指令中添加"warmup"元素:

inbound_services:
- warmup

这会将请求发送到/_ah/warmup,如果需要,您可以在其中进行实例所需的任何其他初始化(例如,启动数据库连接池).

App working with standard environment app engine, python 3.7 and cloud sql (Mysql)

Checking the logs there are some with very high latencies (more than 4 seconds), when the expected are 800ms. All these logs are accompanied by this message:

"This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application."

I understand that when it refers to a new process it refers to the deployment of a new instance (since I use automatic scaling) however the strange thing is that when comparing these logs with the deployment of instances in some cases it matches but in others it does not.

My question is, how can these latencies be reduced?

The app engine config is:

runtime: python37
env: standard
instance_class: F1
handlers:
  - url: /static/(.*)
    static_files: static/\1
    require_matching_file: false
    upload: static/.*
  - url: /.*
    script: auto
    secure: always
  - url: .*
    script: auto
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic
network: {}

解决方案

As you note, these slower requests happen whenever app engine needs to start a new instance for your application, as the initial load is slow (these are called "loading requests").

However, App Engine does provide a way to use "warmup" requests -- basically, dummy requests to your application to start instances in advance of when they are actually needed. This can reduce, but not eliminate the user-affecting loading requests.

This can slightly increase your costs, but it should reduce the loading request latency as these dummy requests will be the ones that eat the cost of starting a new instance.

In the python 3.7 runtime, you can add a "warmup" element to the inbound_services directive in app.yaml:

inbound_services:
- warmup

This will send a request to /_ah/warmup where, if you want, you can do any other initialization the instance needs (e.g. starting a DB connection pool).

这篇关于如何解决“此请求导致您的应用启动了新流程..."导致的应用引擎中的高延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆