1

我正在做從谷歌應用程序引擎到谷歌雲ML(我沒有創建模型)的請求(在線預測),並不時得到異常「等待HTTP響應時超出截止日期從URL」 完整跟蹤此:請求谷歌雲ML超時

Deadline exceeded while waiting for HTTP response from URL: https://ml.googleapis.com/v1/projects/project-id/models/my-model/versions/v3:predict?alt=json (/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py:1552) 
Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/main.py", line 90, in post 
    response = predict(batch_obj=batch_data_obj) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/run_cloud_predict.py", line 88, in predict 
    response = request.execute() 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/oauth2client/util.py", line 135, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/googleapiclient/http.py", line 835, in execute 
    method=str(self.method), body=self.body, headers=self.headers) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/googleapiclient/http.py", line 162, in _retry_request 
    resp, content = http.request(uri, method, *args, **kwargs) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/oauth2client/client.py", line 631, in new_request 
    redirections, connection_type) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/httplib2/__init__.py", line 1659, in request 
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/httplib2/__init__.py", line 1399, in _request 
    (response, content) = self._conn_request(conn, request_uri, method, body, headers) 
    File "/base/data/home/apps/s~project-id/1.402312581449917691/lib/httplib2/__init__.py", line 1355, in _conn_request 
    response = conn.getresponse() 
    File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/gae_override/httplib.py", line 526, in getresponse 
    raise HTTPException(str(e)) 
HTTPException: Deadline exceeded while waiting for HTTP response from URL: https://ml.googleapis.com/v1/projects/project-id/models/my-model/versions/v3:predict?alt=json 

現在我知道,谷歌應用程序引擎對響應60秒限制,這就是爲什麼我做的請求withing任務隊列。我也試過以下的事情:

URLFETCH_DEADLINE = 3600 
urlfetch.set_default_fetch_deadline(URLFETCH_DEADLINE) 
socket.setdefaulttimeout(URLFETCH_DEADLINE) 

我構建的API客戶端這樣的

import httplib2 
from googleapiclient import discovery 
from oauth2client import service_account 

credentials = service_account.ServiceAccountCredentials.from_json_keyfile_name('credentials-file', scopes) 
http = httplib2.Http(timeout=36000) 
http = credentials.authorize(http) 

ml = discovery.build('ml', 'v1', http=http) 
request = ml.projects().predict(name=predict_ver_name, body=request_data) 

有趣的是,有時會發生超時各地的70(69.9,70,70.1等),有時周圍120秒(119.8, 120.1等),這告訴我這可能需要更多的內部Cloud ML處理。 我通過taskqueue並行執行了幾十個請求。成功的響應時間從幾秒到110秒 我只是好奇,如果有人有類似的經驗,或可以給我建議如何解決這個問題,即什麼是導致期限。

回答

0

感謝您發佈您的體驗。 - 有一些啓動成本,取決於可能需要調出多臺服務器來滿足需求的請求速率。 - 您試圖預測的模型大小是多少?較大的型號往往具有較大的啓動成本。

謝謝。