REST API timeout randomly

262 views
Skip to first unread message

Peter Pang

unread,
Jan 17, 2017, 9:06:25 AM1/17/17
to Google Cloud Translation API
I have been using Translation API from last month, I had a small python function on AWS Lambda calling the REST API in this way:

import urllib2
......

URL
= "https://translation.googleapis.com/language/translate/v2?key=${myAPIKey}&source=${source}&target=${target}&q=${q}"
......

def translate(q, s, t):
   
......
    url
= URL.replace('${source}',s).replace('${target}',t).replace('${q}',q)
    result
= urllib2.urlopen(url).read()
   
......

Very straightforward, nothing fancy. I am not using the google-cloud-python library because I need to host my function on AWS Lambda, the cloud library has way too many dependencies that make it impossible to work in AWS Lambda.

However, as I find out later in the log, this request timeout (30sec) once a while without any pattern. Once it started to fail, it failed continuously. But after a few hours, it went back to normal.
  • Quota & load are definitely not the reason, since there are less than 100 call per day, and all of them are short phrases (less than 5 characters).
  • The word & the language are definitely not the reason, since the same request works fine after a few hours.
  • The requests were always sent from AWS Lambda in US East region, so I did not expect network connectivity to be the reason
 
I only saw one post back in 2015 asking about similar question (randomly timeout), and there were no clear answer then that apply to my case.

I hope to get some help from Google Support Team, I will need to use the Translation API a lot more very soon, and the frequent timeout (like almost every day) is going to be a big blocking issue to move on.

Regards,
P.P

Adam

unread,
Jan 17, 2017, 1:07:20 PM1/17/17
to Google Cloud Translation API
Use a shorter timeout for your request and retry on failures, with a backoff:

...
request
= urllib2.Request(url)
response
= urllib2.urlopen(request, timeout=5)
...

In the turbulent realm of cloud APIs, where errors and timeouts can occur without warning, ultimately the best solution is to design your code to handle conditions in a robust way, especially for services like the Translation API which do not have a specific service level agreement.

qian...@grabtaxi.com

unread,
Dec 29, 2017, 9:05:45 AM12/29/17
to Google Cloud Translation API
Hi Peter,

We have met the same issue. The QPS is much lower than the quota, but we still get around 5% timeout. Do you have any conclusion now?

Regard,
Qian

Grab is hiring. Learn more at https://grab.careers

By communicating with Grab Inc and/or its subsidiaries, associate companies and jointly controlled entities (“Grab Group”), you are deemed to have consented to processing of your personal data as set out in the Privacy Notice which can be viewed at https://grab.com/privacy/

This email contains confidential information and is only for the intended recipient(s). If you are not the intended recipient(s), please do not disseminate, distribute or copy this email and notify Grab Group immediately if you have received this by mistake and delete this email from your system. Email transmission cannot be guaranteed to be secure or error-free as any information therein could be intercepted, corrupted, lost, destroyed, delayed or incomplete, or contain viruses. Grab Group do not accept liability for any errors or omissions in the contents of this email arises as a result of email transmission. All intellectual property rights in this email and attachments therein shall remain vested in Grab Group, unless otherwise provided by law.
Reply all
Reply to author
Forward
0 new messages