Best way to load php classes in EC2 - InstanceStore, EBS or S3?

What is the best way to load PHP classes in EC2 in the following scenario (#s for illustrative purposes)? -> 100 EC2 instances running apache and APC -> 100 php classes loaded per request (via __autoload) -> 100 code changes per day between classes (many of the classes contain automatically generated code that is periodically updated via cron).

From what I am collecting, there are 3 ways to upload php class files to EC2:

A. InstanceStore - The local (virtual) hard drive of an EC2 instance -> Code must be pushed separately to each instance. -> Fastest loading since no need to go over the network B. EBS - A volume mounted to a particular instance -> Code must be pushed separately to each instance. -> Slower loading since go over the network C. S3 - A S3 bucket can be 'mounted' to 1 or more EC2 instances -> Code only needs to be pushed once -> Slowest loading since go over the network 

Even if APC is enabled in apache instances, I cannot disable fstat in APC due to uncertainty about how to handle invalidated cached classes in all 100 cases of apache 100 times a day (when changing the code), As a result, if every loading of the class will generate a call on the file system, even if the class was cached by apc (to make the fstat call), would there be a big delay if there were 100 rounds over the network to execute fstat or read the file for each request?

What is the best option (or maybe a new way that is not listed here) for loading class files in the described scenario?

+3
source share
2 answers

Always use an instance with EBS support . Repeat: always use an instance supported by EBS.

When changing the code, you must apply a new instance supported by EBS from a snapshot of the current one. Do not add it to your load balancer.

Apply code changes.

Create a new EBS snapshot. This is your golden standard snapshot for the current round of code changes.

Launch new instances supported by EBS, if necessary, from a snapshot of the new gold standard.

Run the script that gets to your site in new instances that do not yet receive real traffic in order to warm them up (get the PHP classes loaded in APC).

Switch the load balancer so that new instances accept all direct traffic.

Complete old instances.

All of this can and should be automated with an update script. Be sure and enable error checking in your script along the way (for example, I sometimes could not start a new instance due to resource limitations in the availability zone).

The ability to create and destroy new instances as needed is one of the great things about the cloud.

+2
source

Have you thought about serializing the object and putting the whole object in cache-up or putting it in something like memcached?

0
source

Source: https://habr.com/ru/post/898910/


All Articles