在 EC2 中加载 php 类的最佳方式 - InstanceStore、EBS 还是 S3?
在以下场景中,在 EC2 中加载 PHP 类的最佳方法是什么(# 用于说明目的)? -> 100 个运行 apache 和 APC 的 EC2 实例 ->每个请求加载 100 个 php 类(通过 __autoload) ->类之间每天有 100 次代码更改(许多类包含通过 cron 定期更新的自动生成的代码)。
据我所知,有 3 种方法可以在 EC2 中加载 php 类文件:
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
即使在 apache 实例上启用了 APC,我也无法在 APC 中禁用 fstat,因为不确定如何处理缓存类的失效每天在所有 100 个 apache 实例上运行 100 多次(当代码更改时)。因此,如果每个类加载都会生成对文件系统的调用,即使该类已被 apc 缓存(以执行 fstat 调用),那么如果通过网络进行 100 次往返来执行 fstat,是否会出现巨大的延迟或者在每次请求时读取文件?
在所描述的场景中加载类文件的最佳选项是什么(或者可能是此处未列出的新方法)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过序列化对象并将整个对象放入 apc 缓存或将其放入 memcached 之类的东西中?
have you thought about serializing the object and putting the entire object into the apc cache OR putting it into something like memcached?
始终使用 EBS 支持的实例 。重复:始终使用 EBS 支持的实例。
当需要应用代码更改时,从当前实例的快照启动一个新的 EBS 支持的实例。请勿将其添加到您的负载均衡器。
应用代码更改。
创建新的 EBS 快照。这是当前一轮代码更改的黄金标准快照。
根据需要从新的黄金标准快照启动新的 EBS 支持的实例。
运行一个脚本,在尚未占用实际流量的新实例上访问您的网站,以对其进行预热(将 PHP 类加载到 APC 中)。
切换负载均衡器,以便新实例占用所有实时流量。
终止旧实例。
所有这些都可以而且应该通过更新脚本自动化。请务必在脚本中包含错误检查(例如,由于可用区的资源限制,我有时无法启动新实例)。
根据需要创建和销毁新实例的能力是云的奇妙之处之一。
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.