GoogleCloudPlatform/cloud-sql-go-connector

Rate limited when the number of requests is well under the threshold

yukinying opened this issue · 8 comments

Context: rate limiting to SQL admin API seems to be done on a per second bucket rather than per minute.

Outcome: it is very easy to hit the limit as the per second rate is low, and it is common for application servers to warm up the connection pools when the servers get started.

Quote from #413 (comment)

Here is the evidence that the throttling is done by rate per second. Background: my project has a quota 1200 req/min (as I requested for the increase). In theory, if we never get anything further than 20 req/s, we should never be throttled.

Now the interesting observation is that, my project start getting 429 once I reach a rate of 15 req/s. And if you look at the graph, we can infer that we have never reached 1200 req/min, we are far below that.

image

Thanks for the issue @yukinying. I'm going to reproduce it myself and then report back.

I am also hitting the 180 limit constantly with this library.

Does the WithRefreshTimeout() help with this issue?

Our app is simply creating a connection then constantly inserting into the DB. why would this hit the API limit?

Hi @jessequinn,

Can you please open a new issue and provide more details (like a code sample)? Please also see the conversation here and make sure you are using a single Connector object for all connections and not recreating a new one each time.

@kurtisvg we have resolved it based on the referenced conversation. thanks.

@yukinying I did a little bit of testing with both Cloud SQL Admin APIs the connector uses and was unable to reproduce any per second throttling. In my case it seemed the throttling was respecting the per minute quota. I tested both APIs at the same threshold (ratio) as you but on the default quota of 180 req/min, maintaining the req/s at roughly 75% of the quota as you did.

image

I am going to close this for now but if you want to share any additional steps to reproduce or think it warrants another look than feel free to re-open it and I will dig into it a little further.

Thanks and have an awesome day 😄

Thank you for investigating. I suspect this may be throttling only at higher value (1200 req/min). With the latest change in the lib you made, this is very unlikely to be triggered that often. If this happening again, I will collect more data and will re-open.

Thanks @yukinying