سؤال

I am currently using Heroku's Memcached in a Rails 3 app and would like to move over to Elasticache because the pricing is much more favorable. Is this possible? Is the configuration relatively straightforward? Is there anything that I should be aware of as regards the performance?

هل كانت مفيدة؟

المحلول

DANGER: I do NOT recommend using this solution for production use. While this does work, @btucker pointed out that it allows any Heroku-hosted app to access your ElastiCache cluster.

Yes you can. The setup is similar to the guide Heroku has on Amazon RDS. The steps that differ go like this:

  1. Follow the "Get Started with Amazon ElastiCache" guide to create a cache cluster and node
  2. Install the ElastiCache Command Line Toolkit
  3. Allow Heroku's servers ingress to your ElastiCache cluster like the RDS guide explains but replace the rds- commands with elasticache- ones:

    elasticache-authorize-cache-security-group-ingress \
      --cache-security-group-name default \ 
      --ec2-security-group-name default \
      --ec2-security-group-owner-id 098166147350 \
    
      # If your AWS_CREDENTIAL_FILE environment setting is configured,
      # this option is not necessary.
      --aws-credential-file ../credential-file-path.template
    
  4. Set a Heroku config value for your production app with your cluster's hostname:

    heroku config:set MEMCACHE_SERVERS=elasticachehostname.amazonaws.com
    

After that, follow the Memcache Rails setup, and you're set.

نصائح أخرى

No, it isn't recommended you use Elasticache as there is no authentication mechanism with it. As such, anyone can access your cache! This is normally fine as you would use AWS security rules to restrict what machines can access it to yours. However, this obviously doesn't work with Heroku since your app is run on a randomly chosen machine of Herokus.

You could deploy memcache yourself with SASL authentication on an EC2 machine. ElastiCache doesn't really give you anything more than an EC2 machine with memcache pre-installed anyway.

There is another option: MemCachier

(Full disclaimer, I work for MemCachier).

There is another memcache provider on Heroku that is significantly cheaper than the membase provided one. It's called MemCachier, addon home page is here.

It's comparable in price to ElasticCache depending on your cache size and if you use reserved instances or not (at the very large cache sizes ElatiCache is cheaper).

Update (June, 2013): The membase memcache addon has shutdown, so MemCachier is the only provider of Memcache on Heroku.

Please reach out to me if you need any help even if you go with ElastiCache.

It's worth noting that while @ssorallen's answer above will work as described, it also allows ANY heroku-deployed app to access your memcached server. So if you store anything at all confidential, or you're concerned about other people making use of your ElatiCache cluster, don't do it. In the context of RDS you have the access control built into the database, but memcached has no such authentication supported by ElastiCache. So opening up the security group to all of Heroku is a pretty big risk.

There are several Heroku addons that will kinda solve this problem. They provide a SOCKS5 proxy with a static IP address that you can whitelist.

You can also do this yourself by setting up your own SOCKS5 proxy on ec2.

Note the caveats here though: http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html

It's slower, unencrypted, and some NAT monkey business will be required to get it working.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top