GmailAPI: Does using a batch request count just once or n(items) against the quota? - gmail-api

If I use the gmail api to batch fetch 100 mails, does that count 500 quota units or 5? If its 500, then what should the queue setting on my App Engine queue.yaml be so I don't hit the 250 quota units/sec rate limit?

It will count as n items and not one. Also, 250 Quota units per sec is for per user. So, if in your batch request, you have different users, each user will have a 250 Unit Limit.

Related

Gmail API error 429 "User-rate limit exceeded"

Using Gmail API, I keep getting hundreds of error 429 "User-rate limit exceeded".
My script sends 100 emails at a time, every 10 minutes.
Shouldn't this be within the API limits?
The error pops up after only 5 or 6 successful sends.
Thanks
Have a look at the Gmail Usage Limits:
So, if you send 100 emails during a very short time, this corresponds to 10 000 units - thats is 40 times more than the allowed quota per second.
So while short bursts are allowed, if you exceed the quota significantly this might be beyond the scope of the allowed burst.
In this case you should implement exponential backoff as recommended by Google.

Throttle limits for MWS Orders API

In the documentation it states:
The ListOrders and ListOrdersByNextToken operations together share a maximum request quota of 6 and a restore rate of 60.
It was my understanding that this means I could do something like this:
Call ListOrders: request quota = 5, orders downloaded = 100
Call ListOrdersByNextToken: request quota = 4, orders downloaded = 200
Call ListOrdersByNextToken: request quota = 3, orders downloaded = 300
Call ListOrdersByNextToken: request quota = 2, orders downloaded = 400
Call ListOrdersByNextToken: request quota = 1, orders downloaded = 500
Call ListOrdersByNextToken: request quota = 0, orders downloaded = 600
Then, since the restore rate is 60, after 6 minutes my request quota would be back to 6 and I could repeat the process. If I submit all the requests back-to-back, I could pull 600 orders every 6 minutes per merchant.
QUESTIONS:
Is my understanding of the throttle limit correct?
If it is correct, why have I been able to pull over 1000 orders in less than a minute? The only reason the program stops is that the merchant has no more orders to be pulled.
Thanks!
In my testing in February 2017, requests for ListOrdersByNextToken do, in fact, count against your request quota for ListOrders.
It is my understanding that the ...NextToken calls do not count towards the throttling limits. That means you've only made one call as far as throttling is concerned.

Batch Request and Usage Limit

I am using the api sending messages in batches.
I'm getting many messages with code 400 and 500.
I need to control the time between requests when sending multiple batches?
example:
messages.get = 5 per second
If I send 100 messages in a batch request, have to wait 20 seconds to send the next batch?
or
need to send 20 requests with 5 messages each?
At this point probably batches of 10 messages each is best. You can change the per-user limit to 50/sec using the developers console. Even then, you can exceed the limit for a little bit before you start getting quota errors. Either way, if you get quota errors for a user you'll want to do some type of backoff for the user.

How to identify reason of OverQuotaError when sending emails?

I send emails with cron job and task queue usage. The job is executed every 15 minutes and the queue used has the following setup:
- name: send-emails
rate: 1/m
max_concurrent_requests: 1
retry_parameters:
task_retry_limit: 0
But quite often apiproxy_errors.OverQuotaError exception happens. I am checking Quota Details and see that I am still within the daily quota (Recipients Emailed, Attachment Data Sent etc.), and I believe I couldn't be over maximum per minute limit, since the the rate I use is just 1 task per minute (i.e. send no more than 1 mail per minute).
Where am I wrong and what should I check?
How many emails are you sending? You have not set a bucket-size, so it defaults to 5. Your rate sets how often the bucket is replenished. So, with your current configuration, you can send 5 emails every minute. That means if you are sending more than 75 emails to the queue every 15 minutes, the queue will fill up, and eventually go over quota.
I have not tried this myself, but when you catch the apiproxy_errors.OverQuotaError exception, does the message contain any detail as to why it is over quota/which quota has been exceeded?
try:
send_mail_here
except apiproxy_errors.OverQuotaError, message:
logging.error(message)

What is meant by 'bucket-size' of queue in the google app engine?

Google app engine task queues have configuration as (example)
<queue>
<name>mail-queue</name>
<rate>5/m</rate>
<bucket-size>10</bucket-size>
</queue>
Here, what does the 'bucket-size' mean? I could not find a comprehensive documentation about this in google app engine documentation.
Does specifying this as 10 means that if 100 tasks are queued at an instant only 10 of those will be put in the queue and rest will be ignored?
bucket-size is perfectly described here:
Limits the burstiness of the queue's processing, i.e. a higher bucket size allows bigger spikes in the queue's execution rate. For example, consider a queue with a rate of 5/s and a bucket size of 10. If that queue has been inactive for some time (allowing its "token bucket" to fill up), and 20 tasks are suddenly enqueued, it will be allowed to execute 10 tasks immediately. But in the following second, only 5 more tasks will be able to be executed because the token bucket has been depleted and is refilling at the specified rate of 5/s.
If no bucket_size is specified for a queue, the default value is 5.
For your case it means that if 100 messages are queued, only ten are directly being executed and another 5 every next minute. You won't loose any messages, but they will queue up if your bucket-size and rate is too low.

Resources