zatae

zatae

Ecto high database time with Cloud SQL

I have a Phoenix framework project running on Cloud Run. The database is hosted on Cloud SQL.

For some reason, I have really high db response time for even really simple requests and nearly no data:

2022-04-05 20:24:31.035 CEST
18:24:31.035 [debug] QUERY OK source="items" db=298.8ms queue=0.1ms idle=900.7ms
2022-04-05 20:24:31.035 CEST
SELECT t0."id", t0."name", t0."identifier", t0."enabled", t0."user_id", t0."inserted_at", t0."updated_at" FROM "items" AS t0 WHERE (t0."identifier" = $1) ["f2356731-fbd4-4a10-8aa2-c89adf48a98d"]

2022-04-05 20:27:15.077 CEST
18:27:15.076 [debug] QUERY OK source="items" db=692.3ms idle=807.2ms
2022-04-05 20:27:15.077 CEST
SELECT t0."id", t0."name", t0."identifier", t0."enabled", t0."user_id", t0."inserted_at", t0."updated_at" FROM "items" AS t0 WHERE (t0."identifier" = $1) ["f2356731-fbd4-4a10-8aa2-c89adf48a98d"]


SELECT COUNT(*) FROM items;
 count
-------
    16
(1 row)

Any idea ? I tried various type of instance size (both SQL & Run container) but this seems that this is not the problem.

Marked As Solved

zatae

zatae

Finally found what’s was wrong : I have a process running in background, pulling messages from a GCP PubSub and processing it with some db queries (the ones that were really slow). And it seems that without any incoming traffic from the outside (GCP PubSub pull requests obviously aren’t), the container goes in some kind of sleep mode after a few seconds.

To overcome this, you just need to update your container’s configuration CPU allocation and pricing to CPU is always allocated so the container never goes in “sleep mode” and is always awake to query database without any delay. This was more like a GCP issue than a Elixir one but still, it might be useful for some other ppl.

Thanks for your help.

Also Liked

mylan

mylan

Just a shot in the dark, but are they in the same region? And are you using the internal database address or are you using the public address?

joey_the_snake

joey_the_snake

If you show us the explain plan it would help seeing what’s happening at the db level. You can do so using this function:

Using the anlayze: true opt would provide the best info.

Last Post!

dimitarvp

dimitarvp

Nah man, I worked with a lot of stuff but not with CloudSQL. I distinctly remember having used socket_dir once to connect to a local Postgres and it worked. Can’t help you further I am afraid. Must be something in the configuration of CloudSQL or something else.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement