How to increase Google App Engine request timer. Default is 60 sec

无人久伴 提交于 2019-12-24 10:57:47

问题


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.

The Google App Engine request timer (Java/Python/Go) ensures that requests have a finite lifespan and do not get caught in an infinite loop. Currently, the deadline for requests to frontend instances is 60 seconds. (Backend instances have no corresponding limit.) Every request, including warmup (request to /_ah/warmup) and loading requests ("loading_request=1" log header), is subject to this restriction

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.


回答1:


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/modules/

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:

<?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.



来源:https://stackoverflow.com/questions/43115412/how-to-increase-google-app-engine-request-timer-default-is-60-sec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!