Search code examples
sql-servergoogle-cloud-platformgoogle-cloud-sql

Separate SQL server speed too slow in Google Cloud


I was moving all website to google cloud and encounter a performance problem.

I set up a VM instance on Compute Engine and a Cloud SQL server.

And connect the Joomla website from VM to Cloud SQL server using provided IP address. (Seems public IP)

The performance is really slow compared to the website using local database inside the VM itself.

So, my question is, is there a way to find local IP to connect to Cloud SQL since our web server is also on the Google Cloud infra itself.

Or, the only way is to stick with the database inside VM?

Update

I set up the Cloud proxy using this guide.

Can connect to mysql prompt with the proxy now.

But still cannot find a way to let joomla use this cloud proxy to connect to the database.


Solution

  • The fastest, easiest, and most secure way to connect to your Cloud SQL instance from your Compute instance is by using the Cloud SQL Proxy. There are multiple reasons for this, but here are the main ones:

    Secure connections: The proxy automatically encrypts traffic to and from the database using TLS 1.2 with a 128-bit AES cipher; SSL certificates are used to verify client and server identities.

    Easier connection management: The proxy handles authentication with Google Cloud SQL, removing the need to provide static IP addresses.

    There's also the fact that you only need a static and small number of instances (1 in your case) connecting to the database, so you don't really need to overcomplicate your setup, you can just drop this binary into your instance, run it as a daemon, and instantly have a fast lane to your Cloud SQL instance (I use "fast lane" here because the traffic will go through Google Cloud's internal network).

    Setting up the Cloud SQL Proxy comes down to enabling the Cloud SQL API, giving the service account of your intance access to the Cloud SQL API, making sure the binary has execution permissions (chmod +x), and giving it the connection string to the Cloud SQL instance. You seem to be having issues using the Proxy, so if you need more troubleshooting ideas, you can find them in the documentation. The tutorial you've followed should have detailed instructions on how to do these steps.

    After all of that and after making sure the Proxy is running, connecting Joomla to the database should be similar to how you do it via the MySQL client. You should point your Joomla installation to localhost (or 127.0.0.1), give it a set of credentials to access the database itself (you can create database users via the Console), give your Joomla database's name, and that should be it!

    Don't forget that the Proxy needs to be running in TCP mode! That should be as simple as adding =tcp:LOCAL_PORT_TO_LISTEN_ON to the connection string parameter you're passing to the Proxy. Here's an example of how to run the Proxy:

    ./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306