What's the best way to tweak for maximum memory usage?


(mulla) #1

I am running a docker instance at Hetzner on a dedicated box with 32GB of ram and I was wondering if there is a standard way to tweak Discourse, postgres, etc to use as much memory as possible.


(Jeff Atwood) #2

Set the number of Unicorn workers in app.yml to a high number, like 12+. The default is 3 and the minimum is 2. Beyond that I am not sure, @sam or @supermathie?


(Jens Maier) #3

For PostgreSQL, you might want to have a look at pgtune:


(Theron Boerner) #4

(Jeff Atwood) #5

Since this was asked, @sam added a db cache size setting to app.yml. It defaults to 256mb but should definitely be increased if you have lots of memory.

If you have a system with 1GB or more of RAM, a reasonable starting value for shared_buffers is 1/4 of the memory in your system. If you have less RAM you’ll have to account more carefully for how much RAM the OS is taking up; closer to 15% is more typical there. There are some workloads where even larger settings for shared_buffers are effective, but given the way PostgreSQL also relies on the operating system cache, it’s unlikely you’ll find using more than 40% of RAM to work better than a smaller amount.

https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server


(Sam Saffron) #6

I added some comments in our standard and data templates:

As a general rule our defaults are good for 2GB installs, as you raise memory on the box you want to increase both params. (db_shared_buffers and db_work_mem)

It really depends on the size of your site and memory on the box, some ground rules:

  1. You never want to be swapping to disk, if memory is highly constrained, consider decreasing.
  2. You do not want to have a 4GB instance that has 2GB free memory all the time, it is a waste. (unless its a tiny db and you have no way of using the memory)
  3. If you have lots of CPUs you may want to increase the number of unicorn workers which in turn uses memory more efficiently.

See also:


#7

i guess a High Performance option where it favors discourse on backend would be nice