views:

212

answers:

4

I was just reviewing one of my client's applications which uses some old outdated php framework that doesn't rely on caching at all and is pretty much completely database dependent.

I figure I'll just rewrite it from scratch because it's really outdated and in this rewrite I want to implement a caching system. It'd be nice if I could get a few pointers if anyone has done this prior.

  • Rewrite will be done in either PHP or Python
  • Would be nice if I could profile before and after this implementation
  • I have my own server so I'm not restricted by shared hosting
+3  A: 

Since Python is one of your choices, I would go with Django. Built-in caching mechanism, and I've been using this debug_toolbar to help me while developing/profiling.

By the way, memcached does not work the way you've described. It maps unique keys to values in memory, it has nothing to do with .csh files or database queries. What you store in a value is what's going to be cached.

Oh, and caching is only worth if there are (or will be) performance problems. There's nothing wrong with "not relying" with caches if you don't need it. Premature optimization is 99% evil!

inerte
well, my server's memory usage does get a bit high and nearly maxes it on a 512 MB slice, I think it would help.
meder
buh? How would caching things in memory reduce your memory footprint?
SquareCog
+7  A: 

If your site performance is fine then there's no reason to add caching. Lots of sites can get by without any cache at all, or by moving to a file-system based cache. It's only the super high traffic sites that need memcached.

What's "crazy" is code architecture (or a lack of architecture) that makes adding caching in latter difficult.

Alan Storm
I absolutely agree. Caching, especially distributed caching, is only necessary for high-traffic systems. Otherwise, it's more of an overhead than anything else.
Sergey
Caching (especially big memcached stuff) also adds architectural complexity. If your current application is fast enough, then it becomes a question of demand prediction. COULD you end up with significantly more traffic that you do right now? Will a Christmas rush or an article in the local paper see your load grow quickly? If none of these kinds of things apply, sacrificing scalability for simplicity can be a good choice.
Adam Kennedy
+8  A: 

Caching, when it works right (==high hit rate), is one of the few general-purpose techniques that can really help with latency -- the harder part of problems generically describes as "performance". You can enhance QPS (queries per second) measures of performance just by throwing more hardware at the problem -- but latency doesn't work that way (i.e., it doesn't take just one month to make a babies if you set nine mothers to work on it;-).

However, the main resource used by caching is typically memory (RAM or disk as it may be). As you mention in a comment that the only performance problem you observe is memory usage, caching wouldn't help: it would just earmark some portion of memory to use for caching purposes, leaving even less available as a "general fund". As a resident of California I'm witnessing first-hand what happens when too many resources are earmarked, and I couldn't recommend such a course of action with a clear conscience!-)

Alex Martelli
A: 

Depending on the specific nature of the codebase and traffic patterns, you might not even need to re-write the whole site. Horribly inefficient code is not such a big deal if it can be bypassed via cache for 99.9% of page requests.

When choosing PHP or Python, make sure you figure out where you're going to host the site (or if you even get to make that call). Many of my clients are already set up on a webserver and Python is not an option. You should also make sure any databases/external programs you want to interface with are well-supported in PHP or Python.

too much php
I have my own slice on slicehost so I can use whatever :)
meder