Get Started with Amazon RDS on Graviton2 for better price performance
Tags: awsthai, rds, graviton2, database
Published: 2022-07-06 08:10:47

AWS is developing new innovations to meet the needs of users at all times both in terms of efficiency, ease of use, increased features, as well as taking into account the cost optimization as well.

In this post, I will explain how to change Amazon RDS Instance type to use Amazon Graviton2 and provide CloudFormation template for create environment for testing.

### Table of Contents
1. [What's Amazon RDS](#amazon-rds)
2. [What's Amazon Graviton2](#amazon-graviton2)
3. [Amazon RDS type and version that Support Graviton2](#version)
4. [How to change Instance type to Graviton2 based](#change)
5. [Performance testing](#performance)
6. [CloudFormation for testing](#cloudformation)
7. [Conclusion](#conclusion)
8. [References](#references)

<a name="amazon-rds"> 
### What's Amazon RDS
</a>**Amazon Relational Database Service (Amazon RDS)** is Relational database service which store data in Table based consists of row and column. Some tables have relationship using [Primary key](https://en.wikipedia.org/wiki/Primary_key), [Foreign Key](https://en.wikipedia.org/wiki/Foreign_key) and apply [ACID](https://en.wikipedia.org/wiki/ACID) for data consistency.

Amazon RDS help customers to reduce effort in database operations such as provision, backup, patch, encryption, disaster recovery and allow user to enable features easily. So, users can focus on database design, optimize to fulfill  business goals.

Amazon RDS provides 6 relational database engines:
[Amazon Aurora](https://aws.amazon.com/rds/aurora), [PostgreSQL](https://aws.amazon.com/rds/postgresql), [MySQL](https://aws.amazon.com/rds/mysql), [MariaDB](https://aws.amazon.com/rds/mariadb), [Oracle](https://aws.amazon.com/rds/oracle), [Microsoft SQL Server](https://aws.amazon.com/rds/sqlserver)

<a name="amazon-graviton2">
### What's Amazon Graviton2
</a>**Amazon Graviton2** is Processor which AWS create by using 64-bit Arm Neoverse architecture. Amazon Graviton2 provides better performance in lower price.

There're RDS Instance type that Graviton2
- t4g : For dev/test workload 
- m6g : For general purpose workload
- r6g : For memory optimized workload 

In other Services such as EC2, EKS, ECS you can provision Instance type that support Graviton2. 
You can see more details about supported instance [here](https://aws.amazon.com/ec2/graviton)

<a name="version">
### Amazon RDS type and version that Support Graviton2
</a><ul><li>**Amazon Aurora**
<ul><li>Aurora (MySQL 5.7) version 2.09.1 and higher</li>
<li>Aurora PostgreSQL version 11.9 and higher</li>
</ul>
</li>
<li>**Amazon RDS for MySQL**
<ul><li>MySQL version 8.0.17 and higher</li></ul>
<li>**Amazon RDS for PostgreSQL**</li>
<ul><li>PostgreSQL version 12.5 and higher</li></ul>
</li>
<li>**Amazon RDS for MariaDB**
<ul><li>MariaDB version 10.4.13 and higher</li></ul>
</li>
</ul>

Amazon RDS Graviton2 instance provides configurations for use as table below
![Amazon RDS Graviton2 instance Type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz1qzivbw14iso4hazmn.png) you can find all RDS Instance type information [here](https://aws.amazon.com/rds/instance-types)

<a name="change">
### How to change Instance type to Graviton2 based 
:warning: There's Downtime ~10-15 minutes and might higher depend on your data size.
</a><ul><li>**Use AWS Console**<ol><li>Open RDS service console 
[https://console.aws.amazon.com/rds](https://console.aws.amazon.com/rds) ![RDS Console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hz8nus261lf76mw5udjv.png)
</li>
<li>Choose​ RDS database that you would like to change instance type and click **Modify**
![Modify RDS database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q67gac4nfv9dsc79858.png)
</li>
<li>Choose DB instance Class, For this example is **db.m6g.large** 
![DB instance Class](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al4zntu7sv5ipaqoffop.png)
</li>
<li>scroll down and click **Continue**
![Continue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fv365yvn0sa84p8jtaz5.png)
</li>
<li>Choose **Apply immediately** for change RDS instance type immediately, then click **Modify DB instance**
![Apply immediate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oag7y5a6a4c7p8t8p16v.png) After that RDS instance will show status: Modifying ![Modifying](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6atpwgmg1ezkq876gchy.png) it takes time around 10 minutes RDS instance will change to **db.m6g.large** which is Graviton2 instance type successfully ![Complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfof67kp2y8hwokyd7yw.png)</li>
</ol>
</li>
</li>

<li>**Use AWS Command Line Interface (CLI)**
Prepare Access key และ Secret key for access and grant privileges to build RDS instance [https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)

Then, install AWS CLI version 2
[https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)

After configure AWS CLI in Notebook or PC, you can change RDS instance type by using command as below. In this example I'll change RDS instance : rdsgraviton to db.m6g.large

```bash
aws rds modify-db-instance --db-instance-identifier rdsgraviton --db-instance-class db.m6g.large --apply-immediately
```
</li>
</ul>

<a name="performance">
### Performance testing
</a>I'll use **sysbench** which is popular benchmark tool to test performance of RDS MySQL 
In this example, I'll use Amazon Linux2 bastion host on EC2 then, install sysbench and connect to RDS <ol><li>Run this command on bastion host for prepare environment to install sysbench 

```bash
sudo yum -y install git gcc make automake libtool openssl-devel ncurses-compat-libs

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

sudo yum -y install mysql-community-devel mysql-community-client mysql-community-common
```
</li>

<li> Clone sysbench git repository และ install

```bash
git clone https://github.com/akopytov/sysbench.git
cd sysbench
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
```
</li>

<li> Check sysbench version

```bash
sysbench --version
```
</li>

<li> Create MySQL database sbtest for testing

```bash
mysql -u admin -pAWSpassword \
  -hrdsgraviton.c2lep43gswjd.ap-southeast-1.rds.amazonaws.com \
  -P3306 -e 'create database sbtest;'
```
</li>

<li> Prepare and run sysbench 

```bash
sysbench oltp_read_write --db-driver=mysql --mysql-user=admin --mysql-password=AWSpassword --mysql-host=rdsgraviton.c2lep43gswjd.ap-southeast-1.rds.amazonaws.com prepare
sysbench oltp_read_write --db-driver=mysql --mysql-user=admin --mysql-password=AWSpassword --mysql-host=rdsgraviton.c2lep43gswjd.ap-southeast-1.rds.amazonaws.com run
```

This below picture is the result from command sysbench on RDS for MySQL **db.m5.large**
![sysbench-db.m5.large](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ql7qzu1yg28o3wy49hrz.png)

This below picture is the result from command sysbench on RDS for MySQL **db.m6g.large**
![sysbench-db.m6g.large](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63wzswsg40l1tl5qgvnm.png)

Compare the result
![Compare](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zm2tygfypc3h6lvr0tfa.png)

RDS Graviton2 can perform better performance ~10% in this testing environment  
So, you can test on your RDS in environment dev/test before apply on production environment 

Changing RDS instance type to Graviton2 you can gain benefit that no need to change application that using database because there's no change on database engine, version. Only infrastructure hardware that changed.

Regarding cost when compare the result. You can see Graviton2 instance type (db.m6g.large) is lower cost than Intel instance type (db.m5.large) ~10%
![Compare cost](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ek3ozgbj8qlferashi56.png)

Example cost calculation
[https://calculator.aws/#/estimate?id=ed9f868fac8a92e62642455ed394868fecab382f](https://calculator.aws/#/estimate?id=ed9f868fac8a92e62642455ed394868fecab382f) 
</li>
</ol>

<a name="cloudformation">
### CloudFormation for testing
</a>If you would like to deploy environment for provision RDS for MySQL and change Instance Type. And using EC2 as a Bastion host.
You can deploy CloudFormation in Singapore region (ap-southeast-1) 
:warning: There're cost of Resources ~$0.27 per hour.
You can see more details about EC2 cost<ul><li>EC2 : [https://aws.amazon.com/ec2/pricing](https://aws.amazon.com/ec2/pricing)</li>
<li>RDS for MySQL : [https://aws.amazon.com/rds/mysql/pricing](https://aws.amazon.com/rds/mysql/pricing)</li></ul>

**Architecture diagram**
![Architecture diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uoqbll6rxjx4e3hoinqq.png)

**Step to Deploy** <ul><li>Deploy CloudFormation by click [here](https://console.aws.amazon.com/cloudformation/home#/stacks/new?stackName=RDSGraviton2Workshop&templateURL=https://rdsgraviton2-20210528065643-hostingbucket-master.s3-ap-southeast-1.amazonaws.com/RDSGraviton2Workshop.yaml) </li><li>คลิก **Next** ![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zymic6cnlyhx0o8oadc.png) </li><li> In this page you can input parameters as below <ul><li> Change Stack name in this example will use **RDSGraviton2Workshop** </li><li> Change Database password in example will use **AWSpassword** </li><li> Choose EC2 KeyPair for SSH into bastion host </li><li> For Network component such as VPC, Subnet will leave Default. Then, click **Next** </li>
![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n74twbh92pvzudkvj7a.png)</ul>
<li> Scroll down and click **Next**
![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4d3vw21sm4tls2i9klps.png)
</li>
<li> Review CloudFormation and click **Next**
![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz1e744m9wc2l46bf94g.png)</li>

After that CloudFormation will provision resources in this Architecture Diagram and after complete will show status: CREATE_COMPLETE
![CloudFormation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yo3ot0dl84ldzeiajovj.png)</li></ul>

<a name="conclusion">
### Conclusion
</a>You can see RDS Graviton2 instance type will help increase better performance and reduce cost without changing Application.

I recommend to test in dev/test database before apply in production environment.

<a name="references">
### References
</a><ul><li>[Graviton2 Workshop](https://graviton2-workshop.workshop.aws/en)</li>
<li>[Amazon RDS on Graviton2 Processors](https://aws.amazon.com/blogs/aws/new-amazon-rds-on-graviton2-processors)</li>
</ul>

I hope this post can be informative for you to show step-by-step to use Amazon RDS on Graviton2 instance type.
Thank you.