52

I want to host a Redis Server by myself. I compared EC2 to Elasticache. And I would like to know what the disadvantage of EC2 are.

An EC2 tiny instance costs as much as the ELasticache tiny instance but hast 400 mb of ram more. Why should use Elasticache and not setup an own Redis Server on the ec2 tiny isntance?

nohayeye
  • 1,839
  • 2
  • 15
  • 15

5 Answers5

41

tl;dr: Elasticache forces you to use a single instance of redis, which is sub-optimal.

The long version:

I realize this is an old post (2 years at the time of this writing) but I think it's important to note a point I don't see here.

On elasticache your redis deployment is managed by Amazon. This means you're stuck with however they choose to run your redis.

Redis uses a single thread of execution for reads/writes. This ensures consistency w/o locking. It's a major asset in terms of performance not to manage locks and latches. The unfortunate consequence, though, is that if your EC2 has more than 1 vCPU they will go unused. This is the case for all elasticache instances with more than one vCPU.

The default elasticache instance size is cache.r3.large, which has two cores.

Amazon's Elasticache setup menu with defaults populated.

In fact, there are a number of instance sizes with multiple vCPUs. Lots of opportunity for this issue to manifest.

enter image description here

It seems Amazon is already aware of this issue, but they seem a bit dismissive of it.

enter image description here

The part that makes this especially relevant to this question is that on your EC2 (since you're managing your own deployment) you're able to implement multi-tenancy. This means you have many instances of the redis process listening on different ports. By choosing which port to read/write to/from in the application based on a hash of the record's key you can leverage all your vCPUs.

As a side note; an redis elasticache deployment on a multi-core machine should always under perform compared to memcached elasticache deployment on the instance size. With multi-tenancy redis tends to be the winner.

Update:

Amazon now provides separate metrics for your redis instance CPU, EngineCPUUtilization. You no longer need to compute your CPU with the shoddy multiplication, but multi-tenancy is still not implemented.

KeatsKelleher
  • 9,063
  • 4
  • 41
  • 47
  • 2
    Multiple discrete instances is exactly why I run mine on EC2. – Josh Dec 03 '16 at 13:03
  • 1
    "This means you have many instances of the redis process listening on different ports. By choosing which port to read/write to/from in the application based on a hash of the record's key you can leverage all your vCPUs.". So if I run two parallel instances, on different ports, who guarantees that they run on different cores? Will one instance be able to read data other instance wrote? – SexyBeast Apr 23 '17 at 18:51
  • @SexyBeast 1) The operating system is responsible for task switching. In the case you're running multiple instances of redis it makes parallelism possible, but not guaranteed. It's possible if two instances are idle/active subsequently they will be given CPU time on the same core since when the first is done with it the resources are handed back off to the OS. 2) One instance will not be able to read data the other has written. This is required for consistency since redis does not implement locking for reads/writes. – KeatsKelleher Apr 24 '17 at 19:16
  • 1
    Thanks. Can you tell me what advantages do parallelism give me? I mean, Redis works fine being single threaded, if I say didide my keys into three namespaces and shard them into three instances (hoping that they will work on three cores when each core is busy), what advantage will I get compared to when they were all running on the same thread in one instance? Will read/writes be faster? Or data backup faster? In either case RAM consumed will be same, right? – SexyBeast Apr 24 '17 at 19:48
  • @SexyBeast reads and writes will not be faster, no, but you'll be able to do around 3 times more of them assuming you have the RAM and bandwidth available. This is because while one instance is busy with a read/write operation the other are able to handle incoming requests. – KeatsKelleher Apr 26 '17 at 17:18
  • 1
    Okay so that's interesting. So let me get this straight. Imagine my keys have two namespaces - A and B. If both are in one instance, while one request is being processed, if an incoming request comes, it has to wait for some degree of time (however small it is), since it is single threaded. However, if they are running on different cores (provided CPU did allocate multiple cores), one instance can handle the incoming request while the other is till handling the old request. Is that right? But given that Redis finds data lightning quick because it is in-memory, is the gain significant enough? – SexyBeast Apr 26 '17 at 17:42
  • 1
    Since the main value of Redis is as an in-memory caching layer; CPU is not the metric to typically optimize for. – Leo Romanovsky Dec 06 '17 at 08:28
  • @LeoRomanovsky optimizing for CPU is not the point, it's parallelization. When you are able to sidestep the downside of redis' approach to concurrency (single threading) you stand to see a real performance benefit. – KeatsKelleher Dec 07 '17 at 20:52
  • 1
    I get it @KeatsKelleher, I just mostly share the view of SexyBeast in that it is probably not worth the optimization. I've personally never maxed out throughput on Redis itself; it's always been another part of a service. – Leo Romanovsky Dec 18 '17 at 23:55
  • Well, it's worth it when it's worth it. Clearly for you it's not, but there plenty of use cases that max out their redis throughput (e.g. write-through caches for event joining). – KeatsKelleher Dec 22 '17 at 18:02
39

Since I'm lazy, I'd choose Elasticcache over EC2 so that I can avoid some of the operational aspects of managing a Redis instance. With Redis on EC2, you are responsible for scaling, updating, monitoring, and maintenance of the host and the Redis instance. If you're fine dealing with the operational aspects of Redis, then it shouldn't be a problem. A lot of folks over look the costs of the operational aspects of running a Redis instance. Unless you're well-seasoned with Redis, I'd consider Elasticache. I've been using it and have been pretty happy with it so far.

Now, EC2 makes sense when you need custom configurations of Redis that aren't supported by Elasticache.

A̶d̶d̶i̶t̶i̶o̶n̶a̶l̶l̶y̶,̶ ̶i̶f̶ ̶y̶o̶u̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶c̶o̶n̶n̶e̶c̶t̶ ̶t̶o̶ ̶y̶o̶u̶r̶ ̶R̶e̶d̶i̶s̶ ̶i̶n̶s̶t̶a̶n̶c̶e̶ ̶f̶r̶o̶m̶ ̶o̶u̶t̶s̶i̶d̶e̶ ̶o̶f̶ ̶t̶h̶e̶ ̶A̶W̶S̶ ̶e̶n̶v̶i̶r̶o̶n̶m̶e̶n̶t̶,̶ ̶E̶l̶a̶s̶t̶i̶c̶a̶c̶h̶e̶ ̶w̶i̶l̶l̶ ̶b̶e̶ ̶a̶ ̶p̶r̶o̶b̶l̶e̶m̶ ̶a̶s̶ ̶y̶o̶u̶ ̶c̶a̶n̶'̶t̶ ̶u̶s̶e̶ ̶t̶h̶e̶ ̶r̶e̶d̶i̶s̶-̶c̶l̶i̶ ̶t̶o̶ ̶c̶o̶n̶n̶e̶c̶t̶ ̶t̶o̶ ̶a̶ ̶R̶e̶d̶i̶s̶ ̶i̶n̶s̶t̶a̶n̶c̶e̶ ̶t̶h̶a̶t̶ ̶i̶s̶ ̶r̶u̶n̶n̶i̶n̶g̶ ̶i̶n̶ ̶E̶l̶a̶s̶t̶i̶c̶a̶c̶h̶e̶ ̶f̶r̶o̶m̶ ̶o̶u̶t̶s̶i̶d̶e̶.̶

Update: Accessing ElastiCache Resources from Outside AWS

Lastly, if you plan on being on the bleeding edge of Redis, it makes more sense to run your own. But then again, you own the operational bits, monitoring, patching, etc..

Saransh Singh
  • 520
  • 3
  • 11
Ryan J. McDonough
  • 1,467
  • 14
  • 17
  • 5
    Re: "Elasticache will be a problem as you can't use the redis-cli to connect to a Redis instance that is running in Elasticache from outside." That's not true. See [Accessing ElastiCache Resources from Outside AWS](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html). To summarize, you need to have a NAT instance with the proper ingress rules and iptable route defined. – Brenda Bell Apr 11 '16 at 15:59
  • 5
    When this was initially posted, it was not possible to access an ElasticCache instance outside of AWS as the NAT Gateway was not introduced until 12/17/2015. So technically, "That's no longer true" :) – Ryan J. McDonough Sep 14 '16 at 22:11
  • NAT Gateway only made NAT easier... it's not a new concept. – CashIsClay Dec 31 '16 at 16:16
6

Another point is Elasticache is dynamic , you can decrease/increase the memory you use dynamically, or even close the cache(and save $$) if your performance indexes are in the green.

Shachaf.Gortler
  • 5,276
  • 12
  • 38
  • 66
4

Elasticache Pros and Cons:

Pros
- AWS Managed service; so just make use of Redis in application without overhead of the management (leave it to AWS)
- Flexible Instance Types suited for in memory databases.
- If there is any issue with the node, AWS will take care of it (Failover, node replacement, maintenance etc)
- HIPAA compliant service.
- Redis only -> they have their own backup implementation if there is a memory issue which cannot allow BGSAVE.
- Can allow Snapshot creation on a regular basis.
- Easily Scalable both horizontally and vertically (Cluster mode enabled can have upto 250 shards).
- The Configuration Endpoint never changes thus no need to change anything in application in case of failover ( Unless you are using node endpoints )

Cons:
- As the service is AWS Managed, there is very little scope for performance optimization ( through parameter groups ) as you do not get OS level access.
- Not a lot of instance types such as x1 etc.
- Not much customization available Eg: you cannot change the password (Redis AUTH) once created.
- Regular maintenance may be required which can co-incide with the production critical time so extra thing to worry about.
- Not all maintenance event gets notification so unwanted disturbance.
- A lot of time is required to be launched (depends on node type and count of nodes).
- May prove to be expensive.

Custom EC2 Installation Pros and Cons:

Pros
- Extra freedom to optimize and customize
- Maintenance at your own time
- Use whatever resource

Cons
- Need custom logic for maintenance, scaling, recovery from failure and backups, etc.
- Increased operational overhead.

The list is long but these should cover significant differences.

S Square
  • 334
  • 4
  • 10
  • Persistence seems to be of a problem with Elasticache. Or am I wrong? https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/RedisAOF.html – dmigo Jun 14 '19 at 14:56
  • Elasticache ( for redis only ) provides support for snapshot which can be used to save data. Basically it is same as creating RDB which is another way to ensure persistence. Check this out: https://redis.io/topics/persistence#redis-persistence. AOF has limited support as mentioned. – S Square Jun 15 '19 at 07:52
  • [Here](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/FaultTolerance.html#FaultTolerance.Redis) it also says: "Using AOF can't protect you from all failure scenarios. For example, if a node fails due to a hardware fault in an underlying physical server, ElastiCache will provision a new node on a different server. In this case, the AOF is not available and can't be used to recover the data." – dmigo Jun 17 '19 at 13:14
-5

t2.micro vs cache.t2.micro

t2.micro - 1GiB cache.t2.micro - 0.555GiB

But on t2.micro You need OS!. The most of them need about 512MiB.

t2.micro can win maybe only on network performance. You can try run benchmarks and compare.

Alex Veremeenko
  • 336
  • 2
  • 4