Optimization suggestions for thumbnail display and general "smooth" user experience

Nextcloud version: 26.0.0
Operating system and version: Ubuntu 22.04.2 LTS
Apache version: Apache/2.4.52 (Ubuntu)
Database version: MariaDB 10.6.12
PHP version (eg, 7.4): 8.1.2
CPU: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz (4 cores)
Memory: 15.06 GB
OS and installation: 256GB SATA SSD
Data drive: 8TB WD Purple HDD

The issue you are facing:
This is not an issue as such, I am just trying to get best user experience from my new NC installation.
It is a home build, for just 2 users, but I’m a deamding user :slight_smile:
Specs are above.

I’m curently at about half of my 8TB drive, and 99% of data are pictures and videos.

I have done the following so far:

  • installed NC26 on Ubuntu, OS, NC, and all related data is on SATA SSD
  • created one btrfs partition across the WD 8TB rotational HDD for the data, and configured it during NC installation
  • installed preview generator app, and I’m at about half the scan at the moment
  • moved appdata folder that includes preview thumbnails to SSD via mount bind which improved thumbnail display in web interface drastically
  • installed and setup Recognize app which started to show faces
  • installed and setup Memories app and is working fine
  • installed and serup Maps app, and photos are showing correctly on it (about 14k photos with coordinates so far)

What I have NOT done yet, but plan to explore in the following days:

  • opcache
  • redis, APCu, or similar
  • HTTP/2

What I want:
Fast user experience when browsing folders with pictures, or scrolling the Map with thumbnails shown on it. Preferably having whole database and all thumbnails in RAM.

At the moment I can load Map, and thumbnails show up in 20-30 seconds. After that they work relatively smoothly, though if I move map a lot and zoom in/out I get several “black” (unloaded) thumbnails that need few seconds to start loading. Same with browsing folders.
I know part of it is due to my preview-generation still running, my face recognition still working in the background slowly indexing faces, loading my server’s CPU and disk, and some thumbnails still missing, and so on. But I still think it can be even better.

So since I have 16GB RAM, and I’m using around 1.1-1.2GB under load, I started thinking how to load more in RAM.
My database is about 1.5GB, and I’d love it to be cached to memory completely.
My thumbnail cache is about 1GB at the moment, and I’d love it to load in server’s memory as well.

I’ve started reading about memcache techniques for local system (files), and I have some experience with databases, and I know they’ll both cache files and tables once they’re requested.

But I’d love them to be loaded when server starts. Even if my database and thumbnail folders double up by the time everything is fully indexed, that’s still “only” 5GB. If I fill my data drive completely (eventually) that would be just about 10GB of RAM taken by DB and thumbnails. So I’d still be quite good on RAM and would keep having plenty of it spare.

Nextcloud documentation is pretty good on caching, but - it still doesn’t say how to get the effect I’m expecting.

Sure, is server is up for weeks, it will eventually cache everything I regularly use. But I’d still like to use all that RAM to the fullest.

Same/similar with database. Though I could in theory make a small script, or just manually run through the database, run couple “select *” and force most of it into RAM that way, I’d rather have it using something more like MEMORY tables (though obviously permanently, not as temp tables).

I like to learn, and I’m open to suggestions. I’ll keep reading docs and tutorials, but if anyone has any hands-on experience with setting up NC in a similar way, it would save me days and days of reading.

Thanks in advance!

After 2 weeks, I’m somewhat smarter.

I gave up on caching thumbnails, as my preview folder kept growing, and is now stable at 64GB. Bit out of the range :slight_smile:

I’ve set memory limit for database to 3GB, and currently it seems to be sitting at 2GB.

I’ve setup OPcache, APCu, and redis, not sure I feel much of the difference, but at least I feel better about it :slight_smile:

I’ve setup daily mysqldump, unsure if that basically does “select *” on all tables, but at least I have backups done.

I’ve stated using Maps from inside Memories app, it’s much faster at displaying thumbnails.

Experience in LAN is pretty good, server is mostly idle, so power consumption is fine, temperatures are low, but when I want to use it feels snappy enough.

I’ve also taken my time and wrote what I did, more as a reminder to myself, but it ended up being pretty nice guide IMHO, so I’ve published it to github here:

I’ve included sample configs for PHP, MySQL, redis, OPcache, Nextcloud config, and so on. Hopefully someone finds it useful (beside myself).

Cheers!

Just a few notes:

  1. You need HTTP/2 for best performance in most cases.
  2. You can reduce the size of the previews (see this). I think the default is too high for many use cases.
  3. Another optimization I found very useful is placing the appdata folder (that contains the previews) on the SSD, that way it’s much faster.

BTW, the reason Memories is faster at previews is because it pipelines the previews into a single HTTP request as part of the application logic (just saying it’s not a coincidence).

Thanks for the suggestions, that pretty much confirmed I was on a right path :grin:

  • I’ve set preview limits to 1440*1440 (my PC screen is 1440 high, and phones are mostly fine with FHD anyway)
  • I’ve enabled HTTP/2, at least on PC I can confirm it’s working in Chrome
  • and whole appdata folder is on SSD, that truly made the biggest difference (huge jump in performance right away)

And thanks for your work on the Nextcloud apps and all :smiling_face_with_three_hearts: It’s really appreciated :+1: