Memcached Install, Overview & Benchmarks What is Memcached? - - PowerPoint PPT Presentation

memcached
SMART_READER_LITE
LIVE PREVIEW

Memcached Install, Overview & Benchmarks What is Memcached? - - PowerPoint PPT Presentation

Memcached Install, Overview & Benchmarks What is Memcached? Really, its Memcache-d (d as in daemon) TCP/IP service that allows you to store stuff in RAM, somewhat persistently Basically, a persistent hash table Super awesome


slide-1
SLIDE 1

Memcached

Install, Overview & Benchmarks

slide-2
SLIDE 2

What is Memcached?

  • Really, its Memcache-d (d as in daemon)
  • TCP/IP service that allows you to store

stuff in RAM, somewhat persistently

  • Basically, a persistent hash table
  • Super awesome
slide-3
SLIDE 3

Getting Started

  • Download the memcached source code

(http://www.danga.com/memcached/)

  • Download the memcached PHP extension
  • Extract, configure & compile memcached
  • Extract configure & compile php extension
slide-4
SLIDE 4

Compile Memcached

  • Standard configure, make, make instal
  • A few gotchas
  • Memcached requires libevent (http://

www.monkey.org/~provos/libevent/)

  • Even once you get libevent, you may need

a symlink to get memcached to see it.

  • I recommend using a --prefix
slide-5
SLIDE 5

Considerations

  • For testing / small needs, run it on your

web server and give it a few MB of RAM

  • Connections are via TCP/IP, so it can run

anywhere, but obviously you’ll want to strive for minimal network overhead

  • There is NO security, repeat, NO security,

so if you don’t run it on localhost, use some sort of firewall

slide-6
SLIDE 6

Memcache PHP Extension

  • Memcache (notice there is no D here

because we’re not talking about the daemon) is a PECL extension

  • Either use the “pecl install” feature or

download the source code and compile it yourself (then copy to ext/ folder and add to php.ini)

slide-7
SLIDE 7

So Now What?

  • Understand what memcached will and will

not do for you

  • Understand what and when you should

cache

  • Learn how to use the functions provided by

the PHP extension

slide-8
SLIDE 8

What Memcached will not do:

  • Tell you what is stored in it (list keys)
  • Allow you to wildcard delete keys
  • Cache very large items effectively
  • native failover
  • write contents to disk (planned)
slide-9
SLIDE 9

What Memcached will do:

  • Expire things automatically if you set a TTL
  • Expire things when it runs out of space

(first in - first out)

  • Tell you general stats (# connections, bytes

used, etc)

  • Persistent connections
  • Let you flush all the current keys
slide-10
SLIDE 10

What should[n’t] you cache?

  • The more specific a “question” you can ask of the cache,

the more benefit you will get

  • Don’t attempt to cache mysql result sets (many

reasons...)

  • Caching objects or arrays that have had computational

work done on them is good

  • Caching snippets of HTML/XML is better
  • Prevailing wisdom is that objects in cache should be less

(way less) than 1MB

slide-11
SLIDE 11

How to know what’s cached?

  • Create an index in a database table
  • Create an index in memcache...
  • Don’t care, just trust memcache_get() to

return false and handle it appropriately

slide-12
SLIDE 12

Premature Optimization

  • Don’t cache just because it sounds neat
  • Fix your database schema & algorithms first
  • If a script is too slow to run in your test

environment, caching is not a long term solution for you

slide-13
SLIDE 13

So how fast is it?

  • It’s all relative to how much processing you

have to do between a database (or other data source) and a user, but this demo shows between 12x and 40x faster than re- processing every time