'Too Many Connections issue this morning. Anyone else seeing this? [closed]

This just started happening this morning. I noticed that CloudSQL was alerting that there were DB issues. What are other seeing as well?

I don't see we are hitting a CPU, Storage or Memory limit issue.

Severity: Warning

Message: mysqli::real_connect(): (HY000/1040): Too many connections

Filename: mysqli/mysqli_driver.php

Line Number: 192

Backtrace:

Internally I see the connections are fine, but there are two lines that are spooky.

| 189167 | filesuser            | 104.154.65.50:53044 | files      | Query   |    0 | Opening tables        | SET SESSION sql_mode =
                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                    @@sql_mode,
                    " |

and

                           |
| 189170 | unauthenticated user | 104.154.65.50:53052 | NULL       | Connect |    0 | Receiving from client | NULL                                                                                                 |
| 189172 | unauthenticated user | 104.154.65.50:53042 | NULL       | Connect |    0 | Receiving from client | NULL 

I'm assuming that this ^ is from Google Monitoring.



Solution 1:[1]

This SET SESSION sql_mode statement is perfectly normal. Don't worry about it. And, because it sets the session mode, not the global mode, its scope is limited. It's how your php program sets up your server to match the ways it uses SQL.

As for running out of connections: Have you had a big traffic spike? This happens when you have too many php instances running concurrently. It's a common mistake to figure "My server machine has lots of RAM. Let's take the available RAM and divide by the average size of a php instance. That's how many concurrent php instances we should allow." That's incorrect. Paradoxically, more instances cause lower throughput: Your server machine and your MySQL software have to manage the concurrency, which gets expensive and slows you down. Web server machines, especially UNIX-based ones like Linux or FreeBSD, have really robust connection-request queues that handle surges gracefully.

You should limit your concurrent php instances to something like 50, or even less, even if you have the RAM for hundreds of instances.

This is extremely unlikely to be a widespread issue involving multiple customers of the Cloud SQL service you use.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 O. Jones