Slow performance due to per query latency connecting to database?

I have installed discourse and noticed 1 second page loads in some cases. I enabled logging of queries on postgresql and noticed all queries executed in less than 10 milliseconds. However, looking at the /var/www/discourse/log/production.log file (I used docker exec to view this log). I noticed a couple logs that looked something like this:
Completed 200 OK in 724ms (Views: 20.1ms | ActiveRecord: 439.7ms)

Can anybody with knowledge advice on how the ORM framework can carry such overhead. Could i possibly be missing a configuration setting?

That smells… swappy. AR does a lot of memory work to convert data between formats, and if you’re a bit tight on memory, it could end up touching lots of pages that need to be swapped in.

1 Like

It is running on a 16 GB instance and has over 6 GB of free ram available at the moment. Also the instance is using 2 GB RAM at the moment inferred from docker stats.

What are the technical specs of the server? Is this bare metal or cloud?

Are you using our official install ?

I am using the official docker image, but i an running both PostgreSQL and Redis on independent servers. The discourse container is running on Bare metal, HDD, Intel® Xeon® CPU E3-1230 v6 @ 3.50GHz, X86_64 architecture. The PostgreSQL and Redis instances are however running on SSD servers.

1 Like

What does mini profiler show on home page when you drill in. This can be networking. You have to look at logging on the app, not in pg.

If you are paying 10ms round trip tax in every query it adds up super fast

1 Like

Oh, i ended up disabling it as i thought it could be the cause of the issue following this guide:
https://meta.discourse.org/t/rack-mini-profiler-showing-up-in-production-for-admins/14735

I will re-enable it and advice.

Thanks for the latency hint. I all along thought the PostgreSQL server was in the same data center. I just noticed both the Redis server and PostgreSQL server are both 13.6 ms ping time away from the discourse containers. That is unacceptable. Will look into improving this. I had assumed it was around 0.1 ms which is typical when they are in the same data center.

2 Likes

Given we will run 77 queries for admins on a topic page, well that is about 1 second of your delay right there.

5 Likes

Very true. I consider this issue resolved.

2 Likes