本文介绍了如何增加Google App Engine请求计时器.默认值为60秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Google Cloud Engine上运行的PHP脚本,该脚本会触发SQL查询,该查询有时需要60秒钟以上的时间才能执行.如果请求在60秒内未能返回,并且抛出DeadlineExceededError且未捕获该请求,则该请求将中止并返回500内部服务器错误.文档中提到了以下内容.

I have a PHP script that is running on Google Cloud Engine which fires an SQL query and the query sometimes takes more than 60 second to execute.If the request fails to return within 60 seconds and a DeadlineExceededError is thrown and not caught, the request is aborted and a 500 internal server error is returned. Following is mentioned in the documentation.

我已经浏览过此链接,它说明了如何避免此类错误,但是我查询正在一个繁重的数据库上运行,这需要一段时间才能获取所有结果.

I have gone through this link which explains how to avoid such error but my query is running on a heavy database, which takes a while to fetch all results.

我的问题是我如何增加请求计时器以能够运行长时间运行的任务.如果不可能的话,有没有其他选择可以实现这一目标.

My question is how can I increase the request timer to be able to run long running tasks. If not possible is there any alternatives to achieve such a thing.

推荐答案

如果您的代码在请求处理程序中运行,则默认情况下,由App Engine强制执行的最后期限为60秒.您无法更改.请参见本页上图表的截止日期"行/自动缩放"列,位于缩放类型"下:

If your code is running inside a request handler, then by default there is an App-Engine-enforced 60 second deadline. You can't change it. See the "Deadlines" row / "automatic scaling" column of the chart on this page under "Scaling types":

https://developers.google.com/appengine/docs/java/模块/

但是,如果您将模块更改为使用手动缩放"和"B1"-"B4"实例,则此代码将能够运行几个小时.示例:

However, this code will be able to run for some hours if you change your module to use "manual scaling" and a "B1"-"B4" instance. Example:

default/src/main/webapp/WEB-INF/appengine-web.xml:

default/src/main/webapp/WEB-INF/appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
        <application>myapp</application>
        <module>default</module>
        <version>1</version>
        <threadsafe>true</threadsafe>
        <instance-class>B1</instance-class>
        <manual-scaling>
              <instances>1</instances>
        </manual-scaling>
   </appengine-web-app>

在这种类型的实例上,您的请求通常不会在数小时内超时.

On this type of instance, your requests will typically not time out for hours.

这篇关于如何增加Google App Engine请求计时器.默认值为60秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:06