Moreover, if you want to reduce the overhead of MYSQL such as the number of current connections to improve performance, you can use shared memory servers like Redis or Memcached to save user sessions to decrease the number of SQL queries on MYSQL.
In addition, NoSQL database, Couchbase or MongoDB, would be a better alternative to replace MYSQL database. It can dramatically improve the performance of web applications.
As the user traffic grows, you can easily add one EC2 application server on AWS or improve MYSQL/NoSQL database specs to meet this need.
The proposed methods below will teach you how to set up an auto-scale
infrastructure for your applications.
1.Create StartApp Script for Java Application/Tomcat at startup time
Initial an EC2 instance and deploy your Java Application on this EC2 and set up a startApp script below at startup time.
vim startapp
#!/bin/bash
cd /home/weishihhsun/app/
nohup java -jar p2pServer.jar &
sudo cp startapp /etc/init.d
sudo chmod +x /etc/init.d/startapp
sudo update-rc.d startapp defaults 98 02
98 and 02 are the start and stop sequence numbers respectively.
Both are numbers between 00 and 99 and specify how early or late a service is started or killed
By doing so, your Java or Tomcat application would be booted up at startup time.
2. Create an image of EC2 instance on AWS
You need to create an image of EC instance - a clone of this server - by AWS Control UI.3. Setup Auto-Scaling Group
You need to add an image of EC2 instance to the auto-scaling group and set up some thresholds to trigger different types of alarms, such as the usage of CPU, hard disk, and internet traffic.The usage of CPU, for example, is more than 80%, then automatically increase the EC2 instance of a server; if it is below 10%, then decrease the EC2 instance of a server.
To conclude, you have learned how to build a high availability and scalability infrastructure for your applications. By making use of the proposed methods, you can automatically scale up your application servers developed by PHP, Java, C# or C/C++ on AWS, as long as you make your applications independent of the database.