Mark.Wahl reported slow Discourse page loads (~1 second) despite PostgreSQL queries completing in under 10ms. Logging showed high ActiveRecord overhead (e.g., 439.7ms), prompting questions about ORM inefficiency or misconfiguration. mpalmer suggested memory swapping as a possible cause, but Mark confirmed ample free RAM (6GB+) and low container usage (2GB). sam asked for server specs and install method; Mark clarified he uses the official Docker image with PostgreSQL and Redis on separate SSD servers, while Discourse runs on bare metal with HDD and a Xeon E3-1230 v6. sam advised checking Mini Profiler and suspected network latency, noting that even 10ms per query adds up quickly. Mark re-enabled Mini Profiler and discovered a 13.6ms ping between Discourse and its database/Redis servers — far from the expected 0.1ms intra-datacenter latency. sam pointed out that 77 queries per admin topic page at 13.6ms each would account for ~1 second of delay. Mark agreed and considered the issue resolved, attributing the slowdown to network latency rather than ORM or database performance.
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.
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.
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(R) Xeon(R) CPU E3-1230 v6 @ 3.50GHz, X86_64 architecture. The PostgreSQL and Redis instances are however running on SSD servers.
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.