如何解决“由于超过请求最终期限而终止的进程。 (错误代码123)“。在google api? [英] how to solve "Process terminated because the request deadline was exceeded. (Error code 123)" in google api?

查看:259
本文介绍了如何解决“由于超过请求最终期限而终止的进程。 (错误代码123)“。在google api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Google App Engine上部署的Google API(Python)专案。对任何API的每个请求进行数据库连接,执行过程并返回数据并关闭连接。我无法访问任何API,因为它显示

I have a projects deployed on Google App Engine having Google API (Python). Every request to any of API make a database connection , execute a procedure and return data and close the connection. I was not able to access any of API as it was showing

由于超过请求截止日期,进程已终止(错误代码123)和此请求导致为您的应用程序启动新的进程,从而导致您的应用程序代码第一次被加载。因此,此请求可能需要更长的时间,并且比您的应用程序的典型请求使用更多的CPU。错误。

"Process terminated because the request deadline was exceeded. (Error code 123)" and "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." error.

数据库也在云端(Google Cloud SQL)。当我检查有900连接和超过150个实例,但没有处理api请求。这种情况经常发生。所以我重新启动数据库服务器并再次部署API代码来解决这个问题。问题是什么,如何永久解决?这是我的数据库连接的python代码: -

Database is also on cloud (Google Cloud SQL). As I checked there was 900 connection and more than 150 instances were up but no api request was getting handled. This happens frequently. So I restart database server and deploy API code again to solve this issue. What is the issue and how can I solve this permanently ? Here is my python code for database connectivity :-

import logging
import traceback
import os
import MySQLdb
from warnings import filterwarnings

filterwarnings('ignore', category = MySQLdb.Warning)

class TalkWithDB:
    def callQueries(self,query,req_args):
        try:
            if (os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
                db = MySQLdb.connect(unix_socket = UNIX_SOCKET + INSTANCE_NAME, host = HOST, db = DB, user = USER ,charset='utf8',use_unicode=True)
            else:
                db = MySQLdb.connect(host = HOST, port = PORT, db = DB, user = USER, passwd = PASSWORD,charset='utf8',use_unicode=True)

            cursor = db.cursor()
            cursor.connection.autocommit(True)
        try:
        sql = query+str(req_args)
        logging.info("QUERY = "+ sql )
        cursor.execute(sql)     
        procedureResult = cursor.fetchall();
        if str(procedureResult) == '()':
            logging.info("Procedure Returned 0 Record")
            procedureResult = []
            procedureResult.append({0:"NoRecord", 1:"Error"})
            #procedureResult = (("NoRecord","Error",),)
        elif procedureResult[0][0] == 'Session Expired'.encode(encoding='unicode-escape',errors='strict'):
            procedureResult = []
            procedureResult.append({0:"SessionExpired", 1:"Error"})                     
            except Exception, err:
        logging.info("ConnectDB.py : - Error in Procedure Calling :  " + traceback.format_exc())
        #procedureResult = (('ProcedureCallError','Error',),)
        procedureResult = []

        procedureResult.append({0:"ProcedureCallError", 1:"Error"})         

        except Exception, err:
            logging.info("Error In DataBase Connection : " + traceback.format_exc())
           #procedureResult = (('DataBaseConnectionError','Error',),)
        procedureResult = []

        procedureResult.append({0:"DataBaseConnectionError", 1:"Error"})       
# disconnect from server
        finally:
            try:
                cursor.close()
                db.close()
            except Exception, err:
                logging.info("Error In Closing Connection : " + traceback.format_exc())
            return procedureResult


推荐答案

两种可能的改进:


  • 您的实例启动代码可能需要很长时间,请检查启动时间,如果可能,请使用 warmup requests 以减少启动时间。由于增加你的空闲情况似乎帮助,你的启动时间可能太长了。

  • 一个更好的方法是调用外部服务的(如跟谷歌日历)的任务队列用户要求范围之外。这给你一个10分钟的最后期限,而不是60年代的最后期限为用户请求

  • your startup code for instances may take too long, check what is the startup time and if possible use warmup requests to reduce startup times. Since increasing your idle instances seems to help, your startup time may take too long.
  • A better approach would be to call external services (e.g. talk to Google Calendar) in a Task Queue outside of the user request scope. This gives you a 10-min deadline instead of the 60s deadline for user requests

这篇关于如何解决“由于超过请求最终期限而终止的进程。 (错误代码123)“。在google api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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