Cloud MySQL Free Memory

212 views
Skip to first unread message

Devin Homan

unread,
Aug 23, 2019, 10:13:48 PM8/23/19
to Google Cloud SQL discuss
Is it possible to tell MySQL to free-up memory?  When the memory usage gets to a certain point, say 95% used,  Google Cloud MySQL will automatically free the memory and close most connections. Is there any way to manually trigger this behavior?

John Hanley

unread,
Aug 23, 2019, 10:20:34 PM8/23/19
to 'Diogo Almeida' via Google Cloud SQL discuss
Devin,

Why is memory usage a concern on Cloud SQL? The design of MySQL is to use as much memory as possible for caching (around 80%).

If you have a connection count issue, the correct approach is to 1) fix connection leaks in your code 2) use connect pooling.

On 8/23/2019 7:13:50 PM, Devin Homan <de...@flyntlok.com> wrote:

Is it possible to tell MySQL to free-up memory?  When the memory usage gets to a certain point, say 95% used,  Google Cloud MySQL will automatically free the memory and close most connections. Is there any way to manually trigger this behavior?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/178a475b-f525-4428-91d7-6ec39cbc9099%40googlegroups.com.

Devin Homan

unread,
Aug 23, 2019, 11:10:27 PM8/23/19
to Google Cloud SQL discuss
John,

If a SQL operation requires more free memory than is available, the operation will fail but the memory will be freed.  The memory usage does ideally sit at around 80%, but I've had it go above 90% and then go back down to 20%.  The number of connections isn't an issue and the connections are pooled; many of the connections being closed is just what I've had happen when the memory goes back down. I'm guessing this is a behavior that Google has implemented behind the scenes as I cannot find documentation of it, and that the system does this because there is no swap space/virtual memory and running out of memory can cause operating system problems.   It would be nice if I could have a nightly process that triggered this behavior so that there weren't tables cached in memory that may not be needed the next day.   Restarting the database has the same effect, plus more, with more disruption, obviously.  I would think that
FLUSH TABLES

would have this effect, but it does not.  There may be more standard ways of getting MySQL to give-up the memory but it seems that there is already a behind-the-scenes feature for Cloud MySQL to get it to do that.

John Hanley

unread,
Aug 23, 2019, 11:29:47 PM8/23/19
to 'Diogo Almeida' via Google Cloud SQL discuss
MySQL will use as much memory for caching as it can. If MySQL needs memory, cached objects will be evicted.  Trying to manage MySQL memory is not a good idea. Pick an instance size to meet your performance requirements.

Again, I don't understand what problem you are trying to solve.

Where did you come to believe that MySQL queries will fail if the cache is full? Why do you think forcing a cache flush will improve anything? MySQL will (usually) be happy to use the disk albeit at lower performance than memory. If a query requires more physical memory than the instance has, then your only real option is to scale up. Flushing the cache will not achieve this.
--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages