In my relentless pursuit of trying to coax more performance out of my Lemmy instance I read that PostgreSQL heavily relies on the OSs disk cache for read performance. I’ve got 16 GB of RAM and two hdds in RAID 1. I’ve PostgreSQL configured to use 12 GB of RAM and I’ve zram swap set up with 8 GB.

But according to htop PostgreSQL is using only about 4 GB. My swap gets hardly touched. And read performance is awful. Opening my profile regularly times out. Only when it’s worked once does it load quickly until I don’t touch it again for half an hour or so.

Now, my theory is that the zram actually takes available RAM away from the disk cache, thus slowing the whole system down. My googling couldn’t bring me the answer because it only showed me how to set up zram in the first place.

Does anyone know if my theory is correct?

  • moonpiedumplings@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    15 hours ago

    Databases are special. They ofte implement their own optimizations, faster than more general system optimizations.

    For examole: https://www.postgresql.org/docs/current/wal-intro.html

    Because WAL restores database file contents after a crash, journaled file systems are not necessary for reliable storage of the data files or WAL files. In fact, journaling overhead can reduce performance, especially if journaling causes file system data to be flushed to disk. Fortunately, data flushing during journaling can often be disabled with a file system mount option, e.g., data=writeback on a Linux ext3 file system. Journaled file systems do improve boot speed after a crash.

    I didn’t see much in the docs about swap, but I wouldn’t be suprised if postgres also had memory optimizations, like it included it’s own form of in memory compression.

    Your best bet is probably to ask someone who is familiar with the internals of postgres.