| Memcache / memcached basics |
|
|
|
| Written by Juzzy |
| Thursday, 28 April 2011 12:35 |
|
As more and more small-time dynamic websites are seeing increased volumes, one begins to ask: How do I scale out and yet keep costs low? While that can seem to be a very simple questions, there's a magnitude of answers. The one I'll address here is database bottlenecks. Ultimately there is one thing that is making your website / application / whatever slow, that one item is called the bottleneck. You might have 500 things wrong, but usually you only have 1 bottleneck at a time. What happens when you build your web site/application that scales out by web service but still relies on a single database? Well memcache can really help lower the database hits by caching those results from the database and offloading those to a scalable platform. Let's take a look at how I'm doing www.cheap.net: Simply install memcached, and memcache-php5 on your favorite *nix distro (sorry, no windows memcache) I personally like php, so I'll be speaking in terms of php, but you can certainly take these concepts and apply them to any other language with memcache client support. Since I develop on a windows platform, I'll use some logic to determine if I'm in production or dev and my platform:
if ((isset($_SERVER["OS"]) && $_SERVER["OS"] == 'Windows_NT') || ((isset($_ENV["OS"]) && $_ENV["OS"] == 'Windows_NT'))) {
memcache-sessions.php: <?php
Next I wrap all of my mysql calls into an abstraction layer: //basic realtime query
That's the core in a nutshell, in summary, if your website is database driven, but static information, such as a mfg website that's loaded with products and product info, you can crank up the cache expire time to a few days and once it hits cache, you can literally take the database offline and the website will continue to operate. |
| Last Updated on Monday, 02 May 2011 10:17 |


