3 ms·
So I wondered if it is possible to run a forum type community - something along the lines of [elgg][1] or [Friendica][2] - but without the MySQL or other t
by JohnBooty 12y ago
So I wondered if it is possible to run a forum type
community - something along the lines of [elgg][1] or
[Friendica][2] - but without the MySQL or other type of
database backend?
You're attempting to optimize the wrong part of the architecture, I think.
A simple read-only query to SQLite or a NoSQL database is fast - generally just a few milliseconds and often less than one millisecond. The odds of you doing it much faster yourself are low.
Rendering pages is the slow part. Because each forum page you render is going to involve multiple queries to your storage engine (whether you go with SQL or roll your own) and a ton of string manipulation/concatenation.
So what I'd do is....
- Use SQLite for my storage engine. The 256 or 512MB of RAM on a RaspberryPi is plenty for SQLite.
- Cache rendered pages (and/or page fragments) to disk, rather than writing my own storage engine.
I'd use a lazy caching/prerendering strategy. Suppose a discussion thread has 50 pages. One of your mods deletes a post on page 1. Now all 50 pages need to be re-rendered. You have two choices. You can either re-render all 50 pages right away, or you can simply delete all 50 pages right away and re-render & re-cache them as needed, when a user actually requests one of them. I'd do the latter.
I've used this strategy myself. It was a very common paradigm back in the 90s and early 2000s when web servers commonly had hardware specs (700mhz, 256/512MB RAM) that was quite similar to what a RaspberryPi has today. The hardest part of this strategy is getting cache invalidation correct. Every time your code writes to the database, it has to also be aware of which cached pages/fragments it needs to blow away.
(You know the old joke: "There are only two hard things in Computer Science: cache invalidation and naming things.")
- wlievens 12y agoActually there are four hard things: cache invalidation, naming things and off-by-one errors.
- vxNsr 12y agoI don't know if I've ever seen this joke not answered in this way, gets me everytime though.
- tinco 12y agoI think this is the best answer right now. Just build your forum the way you would do it normally and aggressively cache. One addition I would make. Don't cache HTML, cache JSON responses, and build your forum as a one page app. This will allow you to have every response cached while still having customized pages per user (i.e. you could have a user profile on the page that shows a thread).
- JohnBooty 12y agoGood idea. Caching JSON responses as opposed to rendered HTML makes a lot of sense when the server has little RAM.