Use 16GB SSD for Swap on Amazon Linux c3.large Instance

Amazon announced new generation C3 instance types, which are compute optimized instances, available in 5 sizes: c3.large, c3.xlarge, c3.2xlarge, c3.4xlarge and c3.8xlarge with 2, 4, 8, 16 and 32 vCPUs respectively. C3 instances will provide you with the highest performance processors and the lowest price/compute performance compared to all other Amazon EC2 instances. C3 instances also feature Enhanced Networking and SSD-based instance storage. For C3 Instances, each vCPU is a hardware hyperthread from 2.8 GHz Intel Xeon E5-2680v2 (Ivy Bridge) processors.

Setting up c3.large instance with SSDs

When setting up instance, make sure you add both Instance Store volumes. Its up to you how you like to set up your root storage, For this example I opted for 16GB, 480 provisioned IOPS (you need to maintain 30:1 ratio):


Testing the SSD speed

Once set up and server launched, we can use 2nd 16GB SSD (mounted on /dev/sdc) for swap on new Amazon Linux instance c3.large

# Test SSD disk speed
cd /media/ephemeral0/
sudo /bin/dd if=/dev/zero of=outfile.tmp bs=1M count=2048

2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 4.61377 s, 465 MB/s

# Test EBS speed on c3.large
cd ~
sudo /bin/dd if=/dev/zero of=outfile.tmp bs=1M count=2048

2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 70.5714 s, 30.4 MB/s

Setting up swap (and flooding it)

You can see that those 2 x 16GB SSD onboard of c3.large are snappy and fast. Now, let's set up swap to be mounted on 16GB SSD /dev/xvdc
# Utilize 2.nd 16GB SSD for Swap on c3.large
sudo mkswap /dev/xvdc
sudo swapon /dev/xvdc
echo "/dev/xvdc swap swap defaults 0 0" | sudo tee -a /etc/fstab
Little program to test the swap:
sudo yum install gcc -y
memeater.c
#include 
#include 
#include 
#include 

int main(int argc, char** argv) {
    int max = -1;
    int mb = 0;
    char* buffer;

    if(argc > 1)
        max = atoi(argv[1]);

    while((buffer=malloc(16*1024*1024)) != NULL && mb != max) {
        memset(buffer, 0, 16*1024*1024);
        mb+=16;
        printf("Allocated %d MB\n", mb);
        usleep(100000);
    }
    return 0;
}
gcc memeater.c -o memeater
./memeater

Allocated 16 MB
Allocated 32 MB
Allocated 48 MB
Allocated 64 MB
...
Open another SSH window and run the top See the swap being utilized properly.

Conclusion

I love the new c3.large instance on AWS - it is fast and hourly rate is only $0.15. For that, you will get 3.7GB memory, 2 CPUs (For C3 Instances, each vCPU is a hardware hyperthread from 2.8 GHz Intel Xeon E5-2680v2 (Ivy Bridge) processors) and 2 x 16GB SSD. Go for it.

Comments

Popular posts from this blog

Stubbing and Mocking Static Methods with PHPUnit

MongoDB: Remove an Arbiter From a Replica Set

Enable HTTP/2 Support in AWS ELB