Increase time to run code for Google flexible app engine delaying DeadlineExceededError

前端 未结 1 1277
庸人自扰
庸人自扰 2020-12-31 14:46

I have a single function running on Google App Engine Flexible as part of an API call. The structure is something like this

import externalmod
...
...

@app.         


        
1条回答
  •  盖世英雄少女心
    2020-12-31 15:24

    Since i didnt get any answer I kept up the search. I realise many others also have similar issues.

    The first thing to note is that GAE flexible environment does not have most of the standard constraints like in standard environment. This means that DeadlineExceededError does not exist since there is no deadline of 60 sec. All the modules and codes run just like they would on any computer since it is all contained inside Docker containers.

    https://cloud.google.com/appengine/docs/flexible/python/migrating

    Additionally, there is no google.appengine module. Depending on the language being used, all cloud interactions should happen through google.cloud API https://cloud.google.com/apis/docs/overview

    Then what could possibly explain this timeout? I checked the logging -logs in the google cloud project console. I saw that the relevant error is actually [CRITICAL] WORKER TIMEOUT which occurred exactly 30 seconds after the function was called. This has got nothing to do with GAE flex but with the server framework. In my case `gunicorn'.

    The answer is provided here actually https://serverfault.com/questions/490101/how-to-resolve-the-gunicorn-critical-worker-timeout-error/627746

    Basically, using the documentation http://docs.gunicorn.org/en/latest/settings.html#config-file

    the only change needed would be in the app.yaml file

    where earlier it was

    runtime: python
    env: flex
    entrypoint: gunicorn -b :$PORT main:app
    

    gunicorn workers have a default 30 sec timeout

    change this to

    entrypoint: gunicorn -t 120 -b :$PORT main:app
    

    here the timeout is 120 seconds, but depending on some trial and error it can be optimised. This however, solved my particular problem of running a code that takes longer than usual

    0 讨论(0)
提交回复
热议问题