Why is Discourse running so slowly?

I’m not sure which link in the chain is causing the problem. I just finished setting up Discourse on Vagrant on a Windows machine. Everything seems to be working fine, except that it took a good 86000ms (a minute and a half!) for Discourse to load in the browser. Something tells me that it’s not supposed to be that slow. Where can I look for problems that might be causing this?

Potential Causes & Fixes

1. Vagrant + VirtualBox I/O Slowness (Main Cause on Windows)

On Windows, Vagrant uses VirtualBox shared folders, which are notoriously slow — especially for large Ruby/Rails apps like Discourse.

Fix:

Edit your Vagrantfile and use NFS or rsync synced folders (much faster):

config.vm.synced_folder ".", "/vagrant", type: "rsync"

Then reload and provision:

vagrant reload --provision

Note: On Windows, NFS may not work out of the box, so rsync is a safer option. It syncs manually rather than in real time.


2. Discourse’s First-Time Compilation Overhead

The first time you load Discourse, it compiles assets like JavaScript and CSS. This can take 30–60 seconds depending on your system.

Fix:

Once assets are compiled, subsequent loads should be faster. To check if it’s a one-time delay:

  • Run RAILS_ENV=development bundle exec rails assets:precompile
  • Then restart the server and load again.

3. Ruby and Node.js Performance Inside Vagrant

Discourse uses Ruby, PostgreSQL, and Redis — and on Vagrant + Windows, Ruby and Node.js are slower due to file system performance and fewer resources.

Fix:

  • Give more CPU/RAM to the VM: In your Vagrantfile:
config.vm.provider "virtualbox" do |vb|
  vb.memory = "4096"
  vb.cpus = 2
end

Then vagrant reload.


4. DNS or Network Lookup Delays

Sometimes slow page loads happen due to DNS resolution issues or slow hostname lookups inside the VM.

Fix:

Try disabling hostname resolution in PostgreSQL or editing /etc/hosts inside the VM to short-circuit DNS lookups.


5. Try Running Outside of Vagrant

If nothing else works and you’re just developing, consider switching to:

  • WSL2 (Windows Subsystem for Linux) — much faster for Rails apps on Windows.
  • Docker-based setup — Discourse supports Docker installation natively and it’s the recommended production environment.

Diagnose the Delay

Inside your Vagrant VM, run:

top

Look for high CPU/memory usage during load.

Also, run:

time curl http://localhost:3000

This gives a more precise sense of where time is being spent.


Summary of Best Fixes

Problem Fix
Slow shared folders Use rsync instead of VirtualBox defaults
Insufficient VM resources Allocate more RAM and CPU
One-time asset compile Precompile assets
Windows + Ruby slowness Switch to WSL2 or Docker if possible