建议使用以下哪种跨分片数据复制选项?
高性能 mysql 一书建议,为了对博客应用程序进行分片,人们可能需要将评论数据放在 2 个分片上:首先,放在发表评论的人的分片上,然后放在存储帖子的分片上。
因此这就提出了如何可靠地复制这些数据的问题。建议使用以下哪种跨分片数据复制选项?
选项 1:从 PHP 脚本中进行 2 个单独的插入。
优点: a) 逻辑位于应用层。
缺点: a) 用户被保留 2 次插入。 b) 需要在每个尝试插入类似数据的客户端中重复此逻辑。
结论:看起来很合理。
选项2:形成联合表并使用一些触发器来处理重复项的插入。
优点: a) 应用层不需要担心多次插入
缺点: a) 每个分片都需要与其他分片建立联合连接; b) 联合将在 LAN 中的计算机上工作,但在 2 个不同的站点上又如何呢? c) 如果与联合服务器的连接失败怎么办?
结论:这似乎不是一个好主意。
选项 3: 消息传递,例如 RabbitMQ
优点: a) 不同的客户端可以在一个位置插入数据,并且所有订阅者都可以使用该插入。
缺点: a) 复杂; b) 可能会施加开销以托管消息传递服务器和客户端; c) 不确定如何与查找服务一起找到合适的分片
结论:不确定
选项 4:您的建议?
我将非常感谢你的帮助。
High performance mysql book suggests that for sharding a blog application, one may want to put comments data across 2 shards: first, on the shard of a person posting comment, and on the shard where the post is stored.
So this raises the question how to reliably duplicate this data. Which of the following data duplication options across shards is recommended?
Option 1: Make 2 separate inserts from the PHP script.
Pros: a) Logic is in application layer.
Cons: a) User is held for 2 inserts. b) This logic will need to be duplicated in every client trying to insert similar data.
Conclusion: Seems reasonable.
Option 2: Form federated tables and use some trigger to handle the insert of duplicate.
Pros: a) App layer doesn't need to worry about multiple inserts
Cons: a) Every shard need to have federated connection to every other shard; b) Federation will work on machines in LAN, but what about at 2 different sites. c) what if connection to federated server fails.
Conclusion: Doesn't seem like a sound idea.
Option 3: Messaging such as RabbitMQ
Pros: a) Different clients can insert data at one place, and all subscribers can consume the insert.
Cons: a) Complex; b) may impose overhead in order to host messaging server, and clients; c) not sure how will it work with a look-up service to locate appropriate shards
Conclusion: Not sure
Option 4: your suggestion?
I will greatly appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答者:@kdgregory 链接:https://softwareengineering.stackexchange.com/a/134607/41398
Answer by: @kdgregory Link: https://softwareengineering.stackexchange.com/a/134607/41398