views:

1382

answers:

3
+3  Q: 

Memcached on EC2

Am I right in thinking that until I am able to afford dedicated servers or have any spare servers, I could successfully run a small number of memcached servers through EC2?

With the annoucement of the new auto-scaling and load balancing by Amazon today, do you guys think this would be a viable option?

And what would be the basic technical steps you'd recommend me taking?

Thanks

Currently, I have one dedicated server and no memcached servers. I want to use the power of EC2 to setup a few instances and run such memcached servers. That's my current setup.

A: 

How much free memory do you normally have on your current box? Could you not just set up a memcached instance there? I'm thinking that it's possible the latency/overhead/etc. from having remote caches is such that you'd negate any benefits, but perhaps that's not the case.

Rob
Current box has around 512MB currently. I don't fancy running a memcached instance on that and I think that with a sudden burst of large usage, that an instance on my current machine would get full quite quickly.
James
*nod* - you didn't spec out the box you had.
Rob
+4  A: 

To really take advantage of memcached you need to have your memcache communicating with your code as quickly as possible. You may want to investigate how much latency you'd have between the EC2 servers and your own.

Ultimately, you might be better served upping the ram on your current box to something like 4 gigs (should run you about 50 bucks) and putting memcached on the main server. The documentation actually recommends that you install memcached on the same server that is serving out requests. Depending on the size of your application and what it does, a memcached instance with a gig or two may be way more than what you need.

Also, if you're not using a php object caching engine like APC or Eaccelerator, that will also help.

jacobangel
Nitpick: I think you meant "opcode" caching engine; although APC and eAccelerator also come with a simple object cache, the opcode caching is what they're usually installed for.
Rob
I will look into purchasing more memory for my current machine then. Would having lets say 2GB of memcached on my machine, then a couple of amazon servers for extra be workable you think?
James
It depends on the target you're trying to hit. Memcached is one of those "install and tweak" things. Since you're running one dedicated server with 512 mbs, it's possible the 2gb alone may be more than enough. I'd try the 2GB instance, see where that gets you, and then consider the e2 service if that isn't enough.
jacobangel
+5  A: 
  • Load balancing has nothing to do with Memcached -- it uses a hash algorithm for connecting to servers
  • I highly recommend not using autoscaling with Memcached -- adding servers breaks the hashing algorithm and invalidates your cache. Data will go missing and you'll have to recache.
  • You'll want to check the latency from your servers to EC2 -- if it's more than 50ms, you'll be hurting your performance significantly. Well, I'd assume anyway.

You can pull multiple keys (see here for how) with one request to reduce the latency effect, but you'll still take the initial hit. And it also means you need to know all the keys your going to get before you make the call. Otherwise each request adds 50ms (or more) to the execution time of your script.

Consider the data your trying to cache. Is a 64mb slab large enough to help you? You can probably run it on your main servers.

Gary Richardson
Wow, thank you very much for informing me about the autoscale problem. I will definitely take that into account. May I ask, how am I able to pull multiple keys using PHP?
James
I added a link for one method using the Memcached library. All libraries should support it.
Gary Richardson