title: Google Apps Script Web App long-polling and simultaneous executions limit
body: <p>My google script web app is recently hitting qps limits. What would be a better way to improve performance.</p>
  
  <p>I have about 50 active users. I use 15,000 rows google spreadsheet as a database and my app is serving json data requested by users from this spreadsheet. I use long-poll to keep connection alive for 5 min and close it if no update in spreadsheet happens. Then client reconnects. Web App is published to be executed as me. </p>
  
  <p>My polling works like this:</p>
  
  <pre><code>function doGet(e){
      var userHasVersion = e.parameter.userVersion
      while (runningTime &lt; 300001) {
            var currentServerVersion = parseInt(cache.get("currentVersion"),10)
            if(userVersion&lt;currentServerVersion){
              var returndata = []
              for(var i = userVersion+1; i &lt;= currentServerVersion;i++){
                var newData = cache.get(i)
                if(newData!=null){returnData.push(JSON.parse(cache.get(newData)))}
              }
              return ContentService.createTextOutput(JSON.stringify({currentServerVersion,data:returnData })).setMimeType(ContentService.MimeType.JSON); 
            } else {
              Utilities.sleep(20000)
            }
            runningTime = calculateRunningTime()
      }
  }
  </code></pre>
  
  <p>What I have tried so far:</p>
  
  <p>1) I optimized requests with CacheService to reduce calls to Spreadsheet. It helped for few months, but now I'm getting qps errors more and more often. </p>
  
  <p>2) Asking Google team about quotas. They explained me, that there is no published quotas/limits for simultanous executions and they are subject to change without notice. They advised further usage of cacheService and better error handling.</p>
  
  <p>I think to switch from long-polling to short-polling. But it feels like drawback. Should I try to further optimize performance or move to another service? </p>
  
  <p>Would trying to use "execute app as user accessing the app" help? (users should use the same database) </p>
  
  <p>Is Google Script API Executable different from Web App? It looks like it might fit, but I'm not sure if they share the same qps quotas.</p>
  
  <p>I'm also considering GAE service, but I'd like to avoid going over free quota.</p>
  
  <p>Any advice will be much appreciated!</p>