Google Script Quotas - GmailApp.Search - google-apps-script

I've spliced together a script which runs on a 1-minute interval and does a look-up on a Google label:
var mailthreads = GmailApp.search('label:MYLABEL');
Initially, the script ran fine, however within a few days the script began to throw a variety of errors, such as:
Service invoked too many times for one day: gmail
Service using too much computer time for one day
Service invoked too many times in a short time: gmail rateMax. Try Utilities.sleep(1000) between calls.
I have checked Quotas for Google Services with no real explination on what could be causing the script to fail - it ran initially day-to-day without fail, and as the cycle for quotas is 24-hours I would imagine if one 24-hour cycle worked, why didn't the rest?
One theory I have is that the GmailApp.Search query counts each returned item under the label as a single read, and now that the label has grown in size I am reaching a quota limit on reads. Is this how it works, and if not is there anything else I can check?

Related

Measure my current usage consumption on google app script

I have a google app script that execute the following actions:
Read a incoming webhook, write some information on a google spreadsheet, update a google contact and generates several outbound webhooks.
It takes aproximately 5 seconds to execute the whole script.
I would like to know how much times per day I can execute this script. I have seen the following web page but I am not sure in which feature my actions might fit, since there is no description of what those each feature means.
https://developers.google.com/apps-script/guides/services/quotas
Also I check in the google app script dashboard in hope I could find the current usage of my app script, but I only found that my script is execute 500 times per day for an average of 5 seconds per execution. In the future I am going to need to execute this app script more times, but I will like to know which is limit.
¿Where can I find my current app script consumption and which are the quotas for the features I am currently using?
As mentioned in the comments, Google Apps Script has a quota page that shows execution limits on various services.
Please note that you can get quota exception messages if you go near these limits but not go over them entirely.
Since you mentioned that you may need to execute your script more than 500 times a day, you might want to start optimizing your functions to take less time. You can start searching for resources on how to do this, for example in this post: Tracking total execution time Google apps script for an account

High Traffic & Excessive Script Execution Time

I have a container-bound Apps Script Project contained to a Form Response Google Sheet, triggered on form submit. The script runs as me. I'm dealing with execution runtimes 6-8x the nominal run time during peak hours of the day, which seems largely correlated to increased traffic of form submissions. The program follows this series of steps:
Form response collects a string of information and triggers the Apps Script Project to execute
Project creates a copy of a complex Google sheet of a few tabs and a lot of complex formulas
Project pastes the string collected from the form response into this google sheet copy, flushes the sheet, and then returns a string of results calculated within the sheet
Google sheet file is named and the Project creates a unique Drive folder where this sheet eventually gets moved to.
Run complete
The Project performs a wide variety of getValue and SetValue calls throughout the run as it's updating cell values or reading calculated results. Over the last year, I've improved optimization in many ways (i.e. batch calls to getValues or setValues, batch API calls, etc). It's normal run time is 25-45 seconds, but increases to 200+ seconds during my company's peak business hours. Using logs, there is no one particular step that gets hung up. But rather the script lags in all aspects (When it creates the file copy, SpreadsheetApp.flush(), append or delete rows in google other sheets it references by Sheet ID, etc). Although, I'll say a common reason for a failed execution returns the error message "Service Spreadsheets timed out while accessing document with id..." But most of the executions complete successfully, just after a lengthy run.
It seems there is a clear correlation between execution time and traffic. So my questions are:
Can anyone confirm that theory?
Is there a way I can increase the service's bandwidth for my project?
Is there a better alternative to having the script run as me? (mind you I'm performing the rest of my job using Chrome throughout the day while this program continues to automatically run in the background)
This is an Apps Script managed project; it is not tied to a personal GCP Project. Is that a potential factor at play here?

Simultaneous executions limit in google apps script

I am trying to evaluate Google Apps Script (GAS) as one of the component in my overall SaaS. But, I see there is quota limits.
https://developers.google.com/apps-script/guides/services/quotas#current_limitations
Can someone explain what "Simultaneous executions" stands for? Is it 30 Simultaneous executions per a script? Or 30 Simultaneous executions per an account?
I think it's per account. This is important when publishing web apps. When set to execute as "Me", you're limited to 30 simultaneous executions of all users, since they all run as "Me". But if set to execute as "user accessing the web app", then each user gets 30 simultaneous executions. Refer #Tanaike's answer
This also makes sense in case of add-on, where a single script project is published to execute as many users. If simultaneous executions of 30 applies per script, then a add-on could only have 30 users, which is certainly not the case.
Related Error messages from Google documentation:
Script invoked too many times per second for this Google user account. This indicates that the script began executing too many times in a short period. It most commonly occurs for custom functions that are called repeatedly in a single spreadsheet. To avoid this error, code your custom functions so that they only need to be called once per range of data, as explained in the guide to custom functions.
There are too many scripts running simultaneously for this Google user account. This indicates that you have too many scripts executing at once, although not necessarily the same script. Like the exception above, this most commonly occurs for custom functions that are called repeatedly in a single spreadsheet.
Notice both error messages end in "for this Google user account"
Comments from Google/Issuetracker links:
https://issuetracker.google.com/issues/168987850#comment6
https://issuetracker.google.com/issues/36764854#comment8
https://issuetracker.google.com/issues/144888046
https://issuetracker.google.com/issues/161091247#comment2
In almost all cases, Google representative says "for account". You may also create a new issue in the issuetracker for explicit documentation or clarification.

Google Apps Scripts self-starting at night

Context: I have a Google Spreadsheet with some data imported from the external API + some calculations done. API access + calculations are done using Google Apps Script. All those functions are within two files that belong to one project. Today in the morning I noticed multiple
Exception: Service invoked too many times for one day: urlfetch. errors. Strange enough, as neither I nor the second collaborator was working overnight. When I checked executions, it turned out there were multiple executions over the night. It looked as if the document was refreshed every 20-30 minutes.
Questions
How can I check what triggered those functions?
Any ideas how to prevent those executions?

Google Apps Script- trigger-driven time

I'm having a problem with the quotas for Google services, specifically those associated with the trigger -driven Time (clock)
I get the message "Service using too much computer time for one day"
I have 4 different reports, at different times everyday.
Example:
Report 1 : 9-10
Report 2: 11-12
Report 3: 18-19
Report 4: 20-21
Script execution is short about a minute , but for example if the report 1 is scheduled between 9-10, at times it runs from 9:58 - 9:59.
My question is if this happen, will the report and quotas would be exceeded?
Thanks
The exception message "Service using too much computer time for one day", indicates that the script exceeded the total allowable execution time for one day. It most commonly occurs for scripts that run on a trigger, which have a lower daily limit than scripts executed manually.
Apps Script services impose daily quotas and hard limitations on some features. If you exceed a quota or limitation, your script will throw an exception and terminate execution.
Quotas are set at different levels for users of consumer accounts, Google Apps for Your Domain, and Google Apps for Business, Education, or Government.
This is the list of daily quotas as of April 2014. Daily quotas are also refreshed at the end of 24-hour window.
Check also this SO question for more information.