4 ms·
Some things I figured while working on http://thefeelgood.com http://thefeelgood.com 1) Move as much of the work from MySQL to PHP. Things like joins, sorting,
by andr 19y ago
Some things I figured while working on http://thefeelgood.com http://thefeelgood.com
1) Move as much of the work from MySQL to PHP. Things like joins, sorting, etc. are done in PHP. Your PHP nodes are much easier to scale - just throw in a new server when you need it. It won't fix all your scaling problems, but will give you much more time before you need to scale your MySQL.
2) Use memcache for at least the most frequent queries, definitely for everything on the homepage. If invalidation of something gets too hard just use a 10-second expiration or so.
2a) To avoid dogpiling memcache, measure your peak rate of hits on the site. Then, rewrite your cache get function like so:
if (mt_rand(0,$peakRate) == 1)
return false;
else
// get things from cache
3) Think about separating queries in two steps. The first just fetches a list of IDs based on a certain condition, the second fetches the actual items. Cache both steps, with individual cache entries for each item. Make sure you use multi-get.
4) Try to design composite keys instead of autoincrement. For example, for The Feel Good, the post ID is YYYY-MM-DD-U (U = user ID), so just by analyzing the IDs in PHP, I can sort by date, filter future posts (you can schedule posts for tomorrow), analyze user-to-user relationships, etc.
5) Don't be afraid to go around the ORM and write SQL by hand, especially for tricky UPDATEs.