429 Too Many Requests

Created on 17 April 2024, 2 months ago
Updated 21 May 2024, about 1 month ago

Problem/Motivation

When importing even a small sheet (50 rows), I am hitting the Google API rate limit. The migration errors out reporting a "429 Too Many Requests" response on HTTP requests. On a non-paying account, the Google Sheets limit is 300 requests per minute, but even when importing 50 items, I hit the limit almost immediately.

I discovered that when running a migration, the Google Sheet is requested once per row. Hitting the limit even with 50 items, my guess is that 300 req/minute is an average. When making ~15 requests per second, the request limit is hit.

Steps to reproduce

- Fresh D10 install with Migrate Tools, Migrate Plus, and this module.
- Import a sheet into a simple node type like Basic Page with more than 50 rows
- The import has to be fast in order to hit the limit quickly. On my local it creates 35 nodes in about 3 seconds before it hits the rate limit.

Proposed resolution

Two things would help:

1) Import more than a single row per batch operation.
2) Cache the HTTP responses from Google, since the entire sheet is returned, it can be reused within a complete batch process.

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States quicksketch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @quicksketch
  • πŸ‡ΊπŸ‡ΈUnited States quicksketch
  • πŸ‡ΊπŸ‡ΈUnited States quicksketch

    On further investigation, this might be an issue with Migrate Tools module. When running through the API, only a single item is imported per batch request. But running through Drush seems to circumvent the problem. Note when running through Drush, When using Drush, only 2 HTTP requests are made total.

  • πŸ‡ΊπŸ‡ΈUnited States quicksketch

    Having now spent a couple of weeks regularly running into this error of "Too many requests" from Google's API, and having failed to request a rate limit increase from Google themselves, I took a hand at resolving this issue by extending this module's plugin class. Having put it together, I think solving the problem here through a configuration option would be the best solution.

    I would suggest that a YAML configuration option be added like so:

      # Specify a cache lifetime in seconds. This will persist a local cache of
      # remote spreadsheet API request responses. This can be used to lower
      # the number of API requests to fit within rate limits and avoid a
      # "429 Too Many Requests" response from Google. Omit or set to 0 to
      # disable the cache.
      cache_lifetime: 10
    
  • πŸ‡ΊπŸ‡ΈUnited States KarlShea Minneapolis, πŸ‡ΊπŸ‡Έ

    Do you have the cache lifetime implemented in your plugin? If you open a MR I can take a look, I've seen the same myself when hitting through the UI but so far no issues just running with Drush.

Production build 0.69.0 2024