A few simple changes to your Apache config file can greatly improve your micro instance performance.
Last week, I moved my WordPress DB from my t2.micro instance to RDS, with the hope that the change would improve my website performance (I was originally hosting both the web and DB server on the same EC2 instance). The good news is that I no longer get the “database connection” errors I was wont to receive. Bad news is that I’m still having performance problems: now with Apache.
As a stopgap, I configured an alarm to reboot my instance in case I received a status failure. This was a less-than-ideal fix; my server would reboot multiple times a day – sometimes 2-3 times in a 30 minute window!
Last weekend, I finally got a chance to dedicate time to resolving the issue. I spent most of my time looking at the threading options for Apache – prefork, worker, and event. I tried both prefork (the default) and event (which is the less memory-intensive option of the three). I ultimately stayed with prefork, with the following settings (h/t to Marjin van Deele’s post: Tweaking a AWS EC2-micro instance for WordPress).
Two days later, my server seems to be ok. Next step is to strip out some of the preloaded modules from Apache (as outlined in Hayden James’ post: Strip Down Apache to Improve Performance & Memory Efficiency).
Six months ago, I created a Free tier account and got access to a t2.micro instance at no cost (for a year). My plan was to port my old blog over from Blogger (check), freshen up on my Linux skills (check), and to dip my toe into Lambda and DynamoDB waters (check and check).
As the name implies – a micro instance is SMALL (1 vCPU, 1 GiB RAM). Naturally, a micro instance isn’t the most robust. I was constantly having Apache crash, or getting the dreaded WordPress database connection error.
Fortunately, the Free tier also comes with 750 hours of RDS. So, following the instructions Pascal Alma’s website, I proceeded to move my WordPress DB instance from EC2 to RDS.
The move was straight forward…. with a few hiccups:
- I originally planned to use the AWS Database Migration Service, but had a heck of a time getting the endpoints to connect. After 20 minutes of fooling around, I gave up on DMS and instead used the export/import instructions in Mr Alma’s website.
- Security, Security, Security – make sure that you allow communication between your EC2 and RDS servers. I have my EC2 instances in one security group and my RDS instance in another, so I needed to alter the security group inbound rules to allow communication between the server (you’ll need this to both move the data and for ongoing operations).
A few hours later (and honestly what should have taken 30 mins), I was running my blog against the MySQL database instance in RDS.
My only concern is cost; this blog is a hobby and I not looking forward to paying $100 a year for two t2.micro instances (webserver and DB). Maybe I’ll move the web server to a nano instance… food for thought.
For the first few months of it’s existence, this website was slow. I wasn’t sure what the problem was; I thought that maybe I needed more compute (the site is running on a t2.micro EC2 instance). Fortunately, before I switched instance sizes, I did some reading online.
The most helpful site -found here – lists 15 steps to improve performance. After making many of the recommended changes, I found that the largest impact was due to enabling a Content Delivery Network (CDN) and using caching.
I used W3 Total Cache for my cache changes. For my CDN, I used Amazon CloudFront. CloudFront was easy to set-up. Though W3 Total Cache has an option for enabling CDN, I used the WP Offload plugin (as it was already enabled to access my AWS account).
And, just like that, my response times went from 5-8 seconds to 1-3.
In Part 1, I introduced an app that sends an SMS notification when your Fitbit battery is low. Part 2 covered the Authentication Flow of the process. This post describes how the device status is checked and communicated to the user.
The flow is as follows:
- The CloudWatch Scheduler kicks off a Lambda job that pulls registered users from the DynamoDB table. This information is based to a SNS topic, which in turn…
- …kicks off the Lambda function that obtains the Fitbit device info. The Fitbit api is called, and the resulting message is processed by the Lambda function. The device information is stored in and retrieved from the DynamoDB table as needed for processing and history tracking.
- If the result was a success then the a message is sent to the SNS topic for the subscribed user – assuming that the battery status is low AND the user has not already been notified.
- If a “Token Expired” error is returned, then the Lambda function passes the required information to the Refresh User SNS topic. The Lambda function again calls a Fitbit API; this time to refresh the token.
- If the token is refreshed, then the information is saved to the DynamoDB table and passed to the Get Device Info Topic (starting the process all over again)
- If a failure occurs, then a message is sent to the user, directing them to re-authorize the application to access their Fitbit account.
Continue reading “A Fitbit Low Battery SMS Notification using AWS – Part 3”
In Part 1, I introduced an app that sends an SMS notification when your Fitbit battery is low. Part 2 covers the Authentication Flow of the process.
The flow is as follows:
- User accesses the sign-up page (and by default, provides authorization via Fitbit.com). The request is passed through an API Gateway to a Lambda function. The Lambda function calls a Fitbit api to authenticate the user.
- The Fitbit authentication returns to the Lambda code. From there: (3) the token is saved to a DynamoDB database, (4) a message is placed on a SNS topic, and (5) a success response is sent back to the webpage
- The user information (access_token, refresh_token, and mobile number) is saved to a DynamoDB table
- An SNS topic receives the mobile number as a message
- A success message is sent back to the end user.
- The SNS topic (step 4) calls a second Lambda function.
- The Create_User_Topic lambda function creates a sns topic for the newly authenticated user.
- Once the topic is created, a notice is sent to the user’s mobile device – asking to confirm subscription.
- The user confirms the subscription.
Continue reading “A Fitbit Low Battery SMS Notification using AWS – Part 2”