CakePHP中如何主从切换、负载均衡

发布于 2024-09-15 23:14:26 字数 966 浏览 7 评论 0原文

我需要在现有站点中实现主/从/负载平衡。

有人使用这些(或其他)实现来进行主/从切换吗?

我找到的关于如何在 Cake 中实现主/从的资源:。

我在大多数情况下得到了 1) 的工作,但它在某些连接方面遇到了问题。

我欢迎用于主/从实现的新资源、黑客或模组,因为目前我无法理解它。

(我使用atm的蛋糕版本是1.2) (我在 CakePHP 的 google 群组 http:// groups.google.co.uk/group/cake-php/browse_thread/thread/4b77af429759e08f)

I need to implement master/slave/load balancing into an existing site.

Does anyone use these (or other) implementations for master/slave switching?

The resources I found on how to implement master/slave into Cake:.

I'm getting number 1) to work most of the times but it has trouble with some of the joins.

I welcome new sources, hacks or mods for master/slave implementation as for now I can't get my head around it.

(Cake version I am using atm is 1.2)
(I'm cross posting this on CakePHP's google groups http://groups.google.co.uk/group/cake-php/browse_thread/thread/4b77af429759e08f)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幽蝶幻影 2024-09-22 23:14:26

请查看本教程,了解有关多个节点上的主/从的内容。

http://www.howtoforge.com/setting-up-master-master-replication-on-four-nodes-with-mysql-5-on-debian-etch

这可能会帮助您更好地理解。

Take a look at this tutorial in regards to Master/Slave over several nodes.

http://www.howtoforge.com/setting-up-master-master-replication-on-four-nodes-with-mysql-5-on-debian-etch

This may help you understand better.

甜点 2024-09-22 23:14:26

据我所知,如果您的模型与不使用相同行为的模型有关系,就会发生这种情况。 如果这个假设是错误的,请纠正我。

所有模型都有元数据,CakePHP 使用数据库上的 DESCRIBE 查询来累积元数据,如果该数据不存在,您的连接将被破坏。该元数据是特定于数据库配置的。

CakePHP 使用此元数据来填充 $this->_schema 属性。 SQL 连接是使用 $this->_schema 属性中的数据构建的,我想这就是您的问题所在,此 MasterSlave 开关行为引入的数据库没有与模型关联的表的任何模型元数据。

解决方案是更新您的行为,使其仅选择性地切换读取和写入。 将此行为添加到所有相关模型中。即任何使用 hasOne、hasMany 等相关的模型也应该使用相同的行为。

本质上,所有相关的模型都应该写入同一数据库并从同一数据库读取。

此解决方案的好处是您将共享相同的数据库连接。

As far as I can tell this happens if your model has relationships with models that do not use the same behaviour. Please correct me if this assumption is wrong.

All models have meta-data, which CakePHP accumulates using a DESCRIBE query on the database, if this data is not present your joins will be broken. This meta-data is database config specific.

CakePHP uses this meta-data to populate the $this->_schema property. SQL joins are built with data from the $this->_schema property and I guess this is where your issue lies, the database introduced by this MasterSlave switch behaviour do not have any model meta-data for tables associated with the model.

A solution would be to update your behaviour so that it only switches selectively on read and writes. Add this behaviour to all related models. i.e Any model that is related using hasOne, hasMany etc should also use the same behaviour.

In essence all models that are related should write to the same database and read from the same database.

The bonus of this solution is you will share the same database connections.

西瑶 2024-09-22 23:14:26

您的 Web 应用程序似乎是多层的,您需要单独扩展每一层:

  • Web 层,即 CakePHP 应用程序可以分布在多个 Web 服务器上。这很容易做到,因为代码本身是幂等的。你应该研究一下如何对 apache 服务器进行负载平衡,这没什么大不了的。不过,网络服务器具有相当高的吞吐量,因此如果您在这里遇到瓶颈,您可能会改进代码/缓存策略。 (例如,使用 memcache 而不是文件缓存。)如果您依赖于文件系统(例如上传),这会变得有点复杂,因为它必须变得分布式或分离。

  • 数据层。其他人已经链接了如何扩展/负载平衡 MySQL 的各种教程。

尽管首先我建议制定基准。 (过早的优化是万恶之源。)您必须首先知道瓶颈在哪里,吞吐量应该在哪里扩展。通常,您可以首先优化查询、缓存或使内容可缓存。您还必须明确自己的目标:可扩展性?容错能力?

Your web app seems to be multi tier, you need to scale each tier individually:

  • The web layer, i.e. tha CakePHP app can be spread across multiple web servers. This is easy to do, as the code itself is idempotent. You should look into how to load balance apache servers, it is not a big deal. Webservers have quite high throughput though, so if you have a bottleneck here, you might improve your code/caching strategy instead. (Use memcache instead of file caches for example.) If you depend on the file system (uploads for example) this becomes a bit more complex, as it must become distributed or separated.

  • The data layer. There are various tutorials how to scale/load balance MySQL already linked by others.

Albeit first I would suggest to make benchmarks. (Premature optimization is the root of all evil.) You must know first where the bottlenecks are, where the throughput should scale. Often you can optimize queries, caching, or make thing cacheable in the first place. You must also be clear in your goals: scalability? fault tolerance?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文