david rasch — technology. business. life.

david rasch — technology. business. life.

david rasch — technology. business. life. RSS Feed
 
 
 
 

TriPUG and MySQL Talk on Memcache and PHP

Memcache is an extension written by Danga for simple Key/Value pair caching for use with your favorite programming language. In this talk I demonstrate how to install, integrate, and leverage Memcache in PHP (using MySQL for a database). I build a sample application, demonstrate less than desirable performance and finally, return performance with a 100x improvement.

The whole talk and its supporting files can also be downloaded.

Related posts

6 Responses to “TriPUG and MySQL Talk on Memcache and PHP”

  1. 1
    vin:

    hi, are the files/talk still available? links arent working.. thanks :)

  2. 2
    drasch:

    This seems to be misplaced in some “upgrade”. I’ll see if I can locate it and get it back online. Thanks.

  3. 3
    drasch:

    yay, found it! the link should be working again.

  4. 4
    vin:

    this is great.. pardon my ignorance (not a coder), but a question: in the get_recent_posts() function, would/should an ‘else’ separate the ‘cache miss’ conditional from the mysql_query? otherwise wouldnt it always get the db data vs the memcached data? thanks again :)

  5. 5
    drasch:

    Great observation, and you’ve identified an opportunity for further optimization. However, getting the individual posts is a pretty “cheap” sql operation (since you already have the primary keys), so you’ll see most of the performance gain from the data that gets cached to show the most recent post ids.

    This is obviously a simplistic example to demonstrate good performance, but the point applies across the board. You should actually profile your application and see where the most impact can be made with caching. Three things to look at in your profile data are: what’re the operations that take the most time each time they’re run, what operations are run the most often, and what operations consumed the most time overall. Each of these may offer up opportunities for optimization. You’ll often find some things at the slow end of each of these that can make enormous impact.

  6. 6
    vin:

    ok ive had my nose buried in memcached for the past few days and im starting to get it going.. so far i see how it saves db load by sparing reads, but is writing to the db from memcached data a common practice as well? or is there some more efficient way of handling write-intensive operations?

Leave a Reply

Flickr

www.flickr.com
raschnet's items Go to raschnet's photostream

Twitter

    Tags

    Older Stuff