Building Go Applications For AWS Graviton
Learn how to migrate a Go application AWS Graviton EC2 Instances in order to achieve both higher application sustainability and lower costs
- How to build a Go application for AWS Graviton
- How to port an existing Go application to AWS Graviton
About | |
---|---|
✅ AWS Level | 200 - Intermediate |
⏱ Time to complete | 30 minutes |
💰 Cost to complete | Free when using the AWS Free Tier or USD 2.62 |
🧩 Prerequisites | - AWS Account - Amazon DynamoDB Table |
💻 Code Sample | Code sample used in tutorial on GitHub |
📢 Feedback | Any feedback, issues, or just a 👍 / 👎 ? |
⏰ Last Updated | 2023-07-20 |
c5.xlarge
instance-type, and the second will be of c6g.xlarge
instance-type. Once they are running, connect to each instance and install Go.building-go-applications-for-aws-graviton
directory containing all of the appropriate code.goUrlShortener
with a Partition Key of shortURL
for our application to use.
c5.xlarge
instance, navigate to the building-go-applications-for-aws-graviton
directory and run the following command to build the application:goLinkShortener
should be in your working directory.c5.xlarge
instance, navigate to the building-go-applications-for-aws-graviton
directory and run the following command to build the application:goLinkShortener_arm64
should be in your working directory. You can then take and copy this binary to any Linux system running on the arm64 architecture and it will execute. If you try to run it on a Linux system running the x86 architecture it will fail with the following error:c6g.xlarge
instance, navigate to the building-go-applications-for-aws-graviton
directory and run the following command to build the application:goLinkShortener
built natively on the arm64 architecture. Lets move on to the next step and test our application to verify its working as expected.7fcLy5Cqwd
is our application’s identifier for our URL. In a finished application this shortURL value would be used to redirect the user from the shortenedURL to their original URL. For the purposes of this demo, the JSON response is good enough.getFullURL
API, as shown in the following command.c6g.xlarge
and a c5.xlarge
instance we will be performing a load test to verify that the application built for Graviton is working as expected. We discuss various load testing methodologies in the Graviton Technical Guide on GitHub and recommend using a framework like wrk2. wrk2
is a version of wrk
that is modified to produce a constant throughput load and report accurate latency details across various percentiles. I decided to go ahead and use wrk2
to test the shortenURL
function of our application and compare the total requests per second served as well as the latency at each percentile during our load test. I've kept the load tests simple in this guide to illustrate that testing is important.shortenURL
function uses the POST method and requires some data, we need a Lua config file to pass to wrk2. My post.lua
file has the following content:-c
parameter controls how many connections are made during the load test. The -d
test specifies how long the test should run. The -L
parameter enables reporting of latency statistics across various percentiles. The -R
parameter specifies how many requests per second the load test should run with. The -s
parameter allows us to specify our Lua script we defined above.Latency Percentiles | C5.xlarge | C6g.xlarge |
---|---|---|
50 | 31.02ms | 15.02ms |
75 | 42.88ms | 22.82ms |
90 | 49.73ms | 26.64ms |
99 | 57.22ms | 35.42ms |
99.9 | 69.31ms | 49.38ms |
99.99 | 93.38ms | 87.87ms |
99.999 | 180.48ms | 172.80ms |
100 | 230.65ms | 240.64ms |
-R
parameter to 700.Latency Percentiles | C5.xlarge | C6g.xlarge |
---|---|---|
50 | 29.23ms | 17.15ms |
75 | 43.07ms | 24.43ms |
90 | 50.37ms | 28.05ms |
99 | 57.57ms | 36.70ms |
99.9 | 72.06ms | 58.56ms |
99.99 | 312.58ms | 132.74ms |
99.999 | 427.26ms | 327.17ms |
100 | 571.39ms | 728.58ms |
-R
parameter to 800.Latency Percentiles | C6g.xlarge |
---|---|
50 | 17.10ms |
75 | 24.43ms |
90 | 28.03ms |
99 | 37.12ms |
99.9 | 58.49ms |
99.99 | 92.10ms |
99.999 | 217.85ms |
100 | 480.00ms |
-R
parameter to 900.Latency Percentiles | C6g.xlarge |
---|---|
50 | 13.42ms |
75 | 22.45ms |
90 | 26.38ms |
99 | 34.72ms |
99.9 | 56.83ms |
99.99 | 105.60ms |
99.999 | 184.83ms |
100 | 462.59ms |
-R
parameter to 1000.Latency Percentiles | C6g.xlarge |
---|---|
50 | 12.28ms |
75 | 20.78ms |
90 | 25.28ms |
99 | 57.82ms |
99.9 | 1.18s |
99.99 | 2.19s |
99.999 | 2.4s |
100 | 2.49s |
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.