创建友好的流量高峰消息来阻止网站死亡
我们有一个基于 php 的 Web 应用程序,预计 2 天内流量将出现大幅增长。
我们在标准的 Rackspace LAMP 堆栈上进行设置,并将尽可能多地向其投入服务器,但该应用程序的内存和数据库相当密集,因此最大并发用户数会有一定的上限,我们将无法超过该上限我们的时间很少。
我们一直在努力实现 memcached,但由于应用程序的性质,事实证明很难有效地实现。
预计流量只会持续几个小时,我们主要担心的是网站不会崩溃,从而导致销售停止。
显示错误消息“抱歉,我们遇到交通拥堵,请尽快重试”的最简单方法是什么。当服务器负载过重时?
通过这种方式,我们可以为我们正确的 Web 应用程序提供服务,然后当请求队列开始填满时,我们可以只提供简单的静态友好 html 流量消息。
我知道,如果采用幼稚的方法,这意味着一些正要购买商品的人会收到错误消息,然后可能必须返回到流程的开头,这并不理想,但考虑到时间很短-框架,我们只需要网站不崩溃并停止销售。我们该怎么做呢?
任何帮助将不胜感激!
We have a php based web application and are expecting a big spike in traffic in 2 days.
We are set up on a standard Rackspace LAMP stack and will throw as many servers at it as we can but the application is quite memory and db intensive so there will be some ceiling of max concurrent users that we will not be able to exceed given the small amount of time we have.
We have been working to implement memcached but due to the nature of the application it is proving difficult to do effectively.
The traffic is only expected to last for a couple of hours and our main concern is that the site doesn't crash which would bring sales to a halt.
Whats the easiest way to display an error message that says "Sorry we are experiencing heavy traffic, please try again soon." When the servers are experiencing too heavy load?
In this way we could serve our proper web application and then when the request queue starts to fill up then we can just serve the simple static friendly html traffic message.
I know that with a naive approach it will mean that some people who are just about to buy something will get the error message and then might have to go back to the beginning of the process, which isn't ideal, but given the short time-frame we just need the site not to crash and stop sales. How do we do this?
Any help would be hugely appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“重负载”指的是 CPU 负载,那么使用
sys_getloadavg()
,示例:根据您的可用内存和允许的 PHP 进程数量,您可能只想使用
usleep()
相反显示“重负载下”消息。请注意,在睡眠时,该进程仍在占用您的内存和 Web 服务器线程,因此您需要小心这一点 - 您可以根据负载延迟响应,即:负载越高,延迟就越高,这会给 CPU 时间来完成所有工作。
如果您正在运行分布式负载均衡器,您可能希望将这些值保留在 memcached 中,同时将
$cores
变量存储在 APC 或类似的变量中可能会给您带来性能提升。如果您指的是其他类型的负载(例如用户或内存),逻辑是类似的,您需要担心的是获取相关指标并将其存储在 APC 或 memcached 上(如果您需要分布式逻辑)。
PS:ServerFault 可能是提出此类问题的更好地方。
If by "heavy load" you mean CPU load this would be quite easy with
sys_getloadavg()
, an example:Depending on your available memory and the number of allowed PHP processes you might wanna just delay the response for a couple of milliseconds using
usleep()
instead of showing a "under heavy load" message. Be aware that while sleeping, the process is still eating your memory and web server threads so you need to be careful with this - you can delay the response depending on the load, i.e.:The higher the load, the higher the delay, this would give time for the CPU to catch up with all the work.
If you're running a distributed load balancer you might wanna keep these values in memcached, also storing the
$cores
variable in APC or similar will probably give you a performance boost.If you meant other kind of load (like users or memory) the logic is similar, all you need to worry about is to get the relevant metric and store it, either on APC or memcached if you need distributed logic.
PS: ServerFault might be a better place to ask this kind of questions.