As mentioned in part 1 of this series (Creating a LAMP Stack AMI), a common concern among most customers is to choose the right instance type.
It is important to do the capacity planning. Before you choose instance type ask yourself the following three questions:
Is the application Memory intensive CPU intensive or Network intensive? For this question to be meaningful put a monitoring system in place and collect the data for a few weeks of real usage.
What is the expected request count at peak hours?
What is the minimum number of instances you want to run in non-business hours?
Make sure to run at least 2 servers for high availability. During times of fewer loads, choose two m1.small instances for non-business hours like weekends. This would optimize cost instead of using 2 large instances for the same request.
Different instance types have different capacity levels. If the application is memory intensive choose and use m1. class. If the application is CPU intensive then choose and use c1. class.
Network bandwidth varies between different instance types. If the application requires more bandwidth (ex: video streaming applications) choose higher instance types irrespective of Memory or CPU to get better bandwidth.
To know more about each instance types visit the following link.
Start with micro/small instance for any workload. Do the Load run starting with the minimum number of users and increase the load gradually. Also scale the servers vertically or horizontally gradually until it reaches the maximum capacity. This would give a clearer picture of the number of instances required to serve the maximum or minimum load. Closely watch the CloudWatch graphs to understand usage statistics better.
An interesting question at this juncture could be as follows: Can 4 m1.medium instances be preferred to 2 large instances? Yes of course. However, network bandwidth varies from one instance type to other. Given that, it is wise to choose 2 large instances instead of 4 m1.medium instances as it is easier to handle lesser number of instances.
(Note: DB server health needs to be checked when a load test is run. Increasing the app servers count may not improve the performance all the time. If DB queries are the bottleneck, chances are high for a bad performance. Consider scaling up the DB server capacity as well.)
Based on the instance type identified from the load run, tune the PHP memory settings and Apache prefork MPM client connections.
Check out the following links to know more about fine tuning Apache and PHP