feat(cloud-sql): enable lazy refresh for postgres, mysql and sql server connectors#13146
Conversation
| refresh_strategy = RefreshStrategy.LAZY | ||
|
|
||
| connector = Connector(ip_type) | ||
| connector = Connector(ip_type=ip_type, refresh_strategy=refresh_strategy) |
There was a problem hiding this comment.
nit: there is no need to set refresh_strategy as it is only used in one place.
The Cloud SQL Python Connector also allows taking a str for refresh_strategy instead of the custom type.
If we use "lazy" it is a bit more user friendly for the sample as customers will not need to import the custom type of RefreshStrategy 😄
Let's also add to the existing comment to explain why we are setting it.
Something along the lines of "Setting 'refresh_strategy' argument to "lazy" enables lazy refresh mode which is recommended for serverless environments to avoid background refreshes from throttling CPU."
| connector = Connector(ip_type=ip_type, refresh_strategy=refresh_strategy) | |
| connector = Connector(ip_type=ip_type, refresh_strategy="lazy") |
There was a problem hiding this comment.
Same applies to other engine types.
iennae
left a comment
There was a problem hiding this comment.
nit - I think the comment might be a little misleading because it comes across that it's only recommended for serverless environments; AFAIK, it's less useful in non-serverless environments because those instances are long lived so the performance gains may not be as pronounced but it's perfectly ok to use in non-serverless environments as well.
This is correct, it is perfectly acceptable to use I am fine with removing the comment to make the sample more robust and less confusing. 😄 |
Enabled lazy refresh for the Python Cloud SQL connector (Postgres, MySQL, and SQL Server).