数据库分片和Rails[英] Database sharding and Rails

本文是小编为大家收集整理的关于数据库分片和Rails的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

处理铁轨中的碎片数据库的最佳方法是什么?是否应该在应用层,活动记录层,数据库驱动程序层,代理层或其他其他内容上处理碎片?每个人的利弊是什么?

推荐答案

fiveruns有一颗名为 datafabric 复制.可能值得检查.

其他推荐答案

我假设在碎片中,我们正在谈论水平分区而不是垂直分区( spock 我们最终使用自定义mysql代理和以 spock Proxy 为开放源. ActivereCord认为当现实与代理人对话时,它正在与一台MySQL数据库计算机交谈,然后它与一个或多个MySQL数据库进行了交谈,将结果合并/分类,并将其返回给ActiveRecord.您的铁轨代码只需要几个更改.查看Spock代理SourceForge页面,以获取更多详细信息以及我们走这条路线的原因.

其他推荐答案

对于那些没有听说过碎片的人的人:

脱落

本文地址:https://www.itbaoku.cn/post/597611.html

问题描述

What's the best way to deal with a sharded database in Rails? Should the sharding be handled at the application layer, the active record layer, the database driver layer, a proxy layer, or something else altogether? What are the pros and cons of each?

推荐答案

FiveRuns have a gem named DataFabric that does application-level sharding and master/slave replication. It might be worth checking out.

其他推荐答案

I assume with shards we're talking about horizontal partitioning and not vertical partitioning (here are the differences on Wikipedia).

First off, stretch vertical partitioning as far as you can take it before you consider horizontal partitioning. It's easy in Rails to have different models point to different machines and for most Rails sites, this will bring you far enough.

For horizontal partitioning, in an ideal world, this would be handled at the application layer in Rails. But while it's not hard, it's not trivial in Rails, and by the time you need it, usually your application has grown beyond the point where this is feasible since you have ActiveRecord calls sprinkled all over the place. And no one, developers or management, likes working on it before you need it since everyone would rather work on features users will use now rather than on partitioning which may not come into play for years after your traffic has exploded.

ActiveRecord layer... not easy from what I can see. Would require lots of monkey patching into Rails internals.

At Spock we ended up handling this using a custom MySQL proxy and open sourced it on SourceForge as Spock Proxy. ActiveRecord thinks it's talking to one MySQL database machine when reality it's talking to the proxy, which then talks to one or more MySQL databases, merges/sorts the results, and returns them to ActiveRecord. Requires only a few changes to your Rails code. Take a look at the Spock Proxy SourceForge page for more details and for our reasons for going this route.

其他推荐答案

For those of you like me who hadn't heard of sharding:

http://highscalability.com/unorthodox-approach-database-design-coming-shard