Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / MemCache - anyone use it?

Author
Message
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2007 02:05
MemCached (the deamon)
The Deamon you run, usually on linux but it seems to be windows compatible too, sits in the background waiting for connections acting like a warehouse.

MemCache PHP Client
The Client provides an API for your language, in this case, PHP. You then use the commands at hand to put and retrieve stuff from the 'warehouse' which is in RAM - MUCH quicker than disk loading.

What is it?
Its effectively a RAM Disk where you can just dump stuff. That stuff is persistent (eh, between website page loads).
Example: My Thingy Ma Jig Site. I've just installed it on there. I have had to hack a little of the drupal core code, but basically it does a look up in the memcache and if something exists, like the URL Alias array, it grabs that back rather than having to hit the database. Usually you'd hit the database on EVERY page load when lookup up url aliases. Now, once its looked up, it gets commited to the array in the cache. Then the next guy comes along and there is already an existing array from last time with the url's in it! No database hit needed.

MemCache also uses zlib to compress cached data too.

Page load times have almost halved (Pages that were just under 400ms are now about 200ms). So far, its cost me a max of 32Mb RAM (currently using about 200kb of the cache). There are far fewer database hits (I'm getting about an 80% cache hit ratio).

What's the downside? As far as I can see - very little.

You can use MemCache for almost anything - not just PHP. There is one site which has a video which always plays - they use memcache to stream it rather than getting 1000 people to load it off the HDD.

I'm sure some people out there could find a use for this...

[center]
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 22nd Feb 2007 07:16
Used to use something similar when I was running Windows 95 with 32MB of RAM. Allowed some pretty good performance boosts, but tbh nowadays poor performance is more down to poor coding.

Just a shame many developers rely on technology to bridge their own short commings or laziness.

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 22nd Feb 2007 09:34
ahh i must dabble with an actual ramdisk again now that most of machines have 3 gig or more of ram. I used to load OS8 into a ramdisk on a mac and play smaller games with blinding speed.
thanks for reminding me about them again and thanks for pointing out that you can adapt that feature for webdev.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2007 10:28
@Raven:
Quote: "but tbh nowadays poor performance is more down to poor coding"


True and false at the same time.

By "nowadays" I assume you're comparing coding techniques to years gone by. In the past, you programmed something to do one single job, whereas now you tend to program for a wider audience or a wider task range.

An example of this is Drupal - there aren't many sites it cant do (eCommerce, gallery, blog, news, forum, etc). But the downside to its fantastic extendibility is that its a damn fat CMS. It will eat resources like there is no tomorrow.

Another point is that even if you have the best written program in the world, it could probably still gain from caching.

@indi: I read an article about LiveJournal (the guys who origional made this app - it saved their website). They now run 10 servers with a total of 28 instances of memcached. In total they're caching around 30Gb of data!

[center]
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 22nd Feb 2007 14:59
The main problem is a lot of webhosts don't come with it installed. My main gripe with PHP is that it doesn't have a native application object a la ASP, which is pretty much the same as a memcache.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2007 15:04
Quote: "a native application object"

PHP does have objects - but i'm not sure what you mean by this.

Quote: "The main problem is a lot of webhosts don't come with it installed."

Correct. I suggested it to my mate to suggest to his provider and they just threw up excuses. If used correctly, they could save a LOT of system resources!

Also - Shared hosts, although cheap, are getting closed in on by VPS's where you can install all your own software. I'm hosted by a2b2.com and can run whatever I like (within resource and legal limitations).

[center]
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 22nd Feb 2007 15:07
The application object is like a session object, only persistant, and it's often used for caching.

adr
21
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 22nd Feb 2007 16:03 Edited at: 22nd Feb 2007 16:03
Awesome - I might just use this. This will allow me to make proper use of a caching Mapper pattern under PHP.


I'm superfly TNT
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2007 17:35
@Kentaree - there is a session array in PHP - you could dump objects into that, maybe have a key called cache? Never considered that - not a bad idea...

@adr - I dont know what a caching mapper pattern is... All I know is that using the API, you just add things into a "bin" using an ID. The MemCache PHP Extension has its own hashing mechanism to improve lookup times - is this what you're talking about?

PS: I just used MemCache on my TMJ website to cache the cache (In drupal, once a page is created, the object gets serialized into a table and then is just called up and unserialized each time - saves processing time. I added in a line to also add this to the memcache too). My pages that used to take 300ms to load now take 100ms to load and there are next to no hits on the database!

[center]
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 22nd Feb 2007 17:37
Nick, I know there's a session array, but it's not persistant between users. The application object in asp is accessed in much the same way, but it's called application instead of session, and it's the same for all users.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Feb 2007 17:38
Ohhh i see! That's quite cool actually. Like a REAL global array - accessible by all. Nifty idea.

[center]

Login to post a reply

Server time is: 2024-11-18 06:53:07
Your offset time is: 2024-11-18 06:53:07