This part is pretty straight forward, we will effectively use the ephemeral SSD as the primary storage device for our EC2 instance but at the same time use
lsyncd asynchronously to replicate files to another directory mounted on an EBS volume where you can get the persistence of EBS and the durability of snapshots to S3.
One downside to this approach is when you recovering from failure, a manual step of initially copying data from EBS back onto SSD will be required. Note however if you are planning to use something like this in production it is recommended to use a high availability solution by which you synchronise to another node in a different availability zone as well as locally to EBS.
One would say, why the hassle I could just run a
rsync job over a cron every 5 minutes which would not be wrong. Or you could use lsyncd which offers a hell of a lot more than a good old cron job.
lsyncd is written in Lua and the project page describes it as follows:
lsyncdwatches a local directory trees event monitor interface (
fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronise the changes.
So the clever thing going on here is that synchronisation happens when events are detected on the directory tree not at a set interval which is much more efficient. lsyncd default behaviour lets you do the synchronisation in
direct. The latter can be used to keep two local directories in sync using
/bin/mv which is faster than
rsync especially after the initial sync.
lysncd works well when synchronising local or remote directories with low profile of expected changes. For systems under heavy write load, block level replication will fair much better in terms of performance. AWS Re:Invent STG 401 has some ideas on how to use DRBD for example to build highly available NFS and CIFS systems in EC2.
Installation and Configuration
Installing and configuring
sync is a doddle, I am going to use asciinema to show you a terminal recording of what I did to install it and test it, hopefully this will be easier than before to follow along:
I didn’t perform any performance tests this time because we expect to see native SSD performance. See: