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 are for illustrative purposes)? -> 100 EC2 instances running apache and APC -> 100 php classes loaded per request (via __autoload) -> 100 code changes per day between the classes (many of the classes contain auto-generated code that are periodically updated via cron).

From what I gather, there are 3 ways to load the php class files in 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 with APC enabled on the apache instances, I am not able to disable fstat in APC due to being unsure of how to handle the invalidation of the cached classes on all 100 apache instances 100+ times a day (when code changes). As a result, if each class load will generate a call to the filesystem even if the class was cached by apc (to do the fstat call), wouldn't there be huge latency if there were 100 round trips over the network to do fstat or read the file on every request?

What is the best option (or maybe a new way that is not list here) to load class files in the scenario described?


Always use an EBS backed instance. Repeat: Always use an EBS backed instance.

When code changes need to be applied, spin up a new EBS backed instance from a snapshot of the current one. Do not add it to your load balancer yet.

Apply code changes.

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

Launch new EBS-backed instances as needed from the new gold standard snapshot.

Run a script that hits your website on the new instance(s), which are not yet taking real traffic, to warm them up (get the PHP classes loaded into APC).

Switch your load balancer so that the new instances are taking all live traffic.

Terminate the old instances.

All of this can and should be automated with an update script. Be sure and include error checking in your script along the way (for example, I have occasionally been unable to fire up a new instance due to resource constraints in the availability zone).

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

have you thought about serializing the object and putting the entire object into the apc cache OR putting it into something like memcached?

Need Your Help

Can I use Windows Environment Variables into Eclipse Workspace path?

eclipse path environment-variables

When you start Eclipse for the first time, it asks you the path for the workspace. Now, normal path should be C:\Users\USERNAME\Workspace but, if I try to set %USERPROFILE%\Workspace it doesn't wor...

Xcode beginner - compiling issue

c xcode

I am very new to the Xcode environment. I would like to compile some .c and .cpp files. So I created a project with the generic c++ plugin (is it the right choice?). It builds the file with success...