负载均衡和APC
我对使用负载均衡器设置为 PHP 应用程序提供服务的 Web 服务器的场景感兴趣。
负载均衡器后面将有多个带有 APC 的 Web 服务器。所有请求都必须经过负载均衡器,然后负载均衡器将其发送到其中一台 Web 服务器进行处理。
我知道 memcached 应该用于分布式缓存,但我认为在每台计算机上使用 APC 缓存可以缓存诸如应用程序配置和其他对象等在任何服务器上不会不同的对象,效果会更好表现。
该应用程序还有一个管理员区域。还可以通过负载平衡器(例如 site.com/admin)访问它。在这种情况下,如何调用apc_clear_cache
来清除所有服务器上的APC对象缓存?
I am interested in a scenario where webservers serving a PHP application is set up with a load balancer.
There will be multiple webservers with APC behind the load balancer. All requests will have to go through the load balancer, which then sends it to one of the web servers to process.
I understand that memcached should be used for distributed caching, but I think having the APC cache on each machine cache things like application configurations and other objects that will NOT be different across any of the servers would yield even better performance.
There is also an administrator area for this application. It is also accessed via the load balancer (for example, site.com/admin). In a case like this, how can I call apc_clear_cache
to clear the APC object cache on ALL servers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在网络外部,您有一个公共 IP,用于将所有请求路由到分配负载循环的负载均衡器,因此在外部,您无法一次请求清除每台服务器上的缓存,因为您不知道是哪一台服务器任何给定时间都在使用一个。然而,在你的网络内,每台机器都有自己的内部IP,可以直接调用。知道了这一点,你就可以做一些在外部有效的有趣/奇怪的事情。
我喜欢的解决方案是能够点击单个 URL 并完成所有操作,例如 http://www.mywebsite/clearcache.php 或类似的东西。如果您也喜欢,请继续阅读。请记住,如果您愿意,您可以对其进行身份验证,以便您的管理员可以点击此按钮或以任何方式保护它。
您可以创建逻辑,在其中可以从外部发出一个请求来清除所有服务器上的缓存。无论哪个服务器收到清除缓存的请求,都将具有相同的逻辑来与所有服务器通信以清除其缓存。这听起来很奇怪,有点弗兰肯斯坦,但这里的逻辑假设我们内部有 3 台 IP 为 10.232.12.1、10.232.12.2、10.232.12.3 的服务器:
请告诉我这是否适合您。我已经在 .NET 和 Node.js 中完成了类似的操作,但还没有在 PHP 中尝试过,但我确信概念是相同的。 :)
Externally in your network you have a public IP you use to route all your requests to your load balancer that distributes load round robin so outside you cannot make a request to clear your cache on each server one at a time because you don't know which one is being used at any given time. However, within your network, each machine has its own internal IP and can be called directly. Knowing this you can do some funny/weird things that do work externally.
A solution I like is to be able to hit a single URL and get everything done such as http://www.mywebsite/clearcache.php or something like that. If you like that as well, read on. Remember you can have this authenticated if you like so your admin can hit this or however you protect it.
You could create logic where you can externally make one request to clear your cache on all servers. Whichever server receives the request to clear cache will have the same logic to talk to all servers to clear their cache. This sounds weird and a bit frankenstein but here goes the logic assuming we have 3 servers with IPs 10.232.12.1, 10.232.12.2, 10.232.12.3 internally:
Let me know if this works for you. I've done this in .NET and Node.js similar but haven't tried this in PHP yet but I'm sure the concept is the same. :)