考虑在 Rails 上进行扩展,您会编写手写 SQL 吗?使用续集宝石?

发布于 2024-12-12 01:41:23 字数 165 浏览 7 评论 0原文

如果我想根据授权规则(位置和用户角色)将数据库分布在不同的计算机上来扩展 Rails 应用程序。因此,归属于该位置的任何资源都将位于专用于该位置的数据库中。

我应该开始进行基本的 SQL 编写,使用 Sequel gem 之类的东西还是保留 ActiveRecord 的美好和魔力

If I wanted to scale a Rails application by distributing its database on a different machine based on its authorization rules (location and user roles). So any resource attributed to that location would be sitting in a database dedicated to that location.

Should I get down to basic SQL writing, use something like Sequel gem or keep the niceness and magic of ActiveRecord?

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

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

发布评论

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

评论(2

爱*していゐ 2024-12-19 01:41:23

确实,原始 SQL 执行速度超过了 ActiveRecord 的神奇查询的执行速度。但是,如果您谈论扩展,那么就会出现这样的问题:当应用程序真正变大时,查询的管理能力如何。

到目前为止,许多复杂的数据库操作可以通过缓存、适当的索引和适当的预加载来很好地管理。在某些情况下,MySQL 视图也有助于提高性能,Rails 公平地对待 MySQL 视图。在此之后,如果能够解决非常慢的查询,那么将它们转换为原始 SQL 并节省一些时间可能是值得的。此外,Rails 还提供数据库查询缓存。 MySQL还有一个缓存机制。在直接执行原始 SQL 之前,我会确保这些选项(实际上更多的是避免不必要的连接,因为连接操作是资源密集型的)无法提供我想要的东西。希望这有帮助。

It is true that raw SQL execution speed is more than execution of the ActiveRecord's nice magical queries. However, if you talk about scaling then there comes this question of how well would the queries be manageable when the application really grows large.

By far, a lot of complicated database operations can be managed well by caching, and proper indexing and proper eager-loading. In some cases MySQL views also help to improve performance, and Rails treats MySQL views fairly. After this, if one is able to corner out the really slow queries, then it might be worth it to convert them to raw SQL and save some time. Also, Rails offer caching of the database queries. MySQL also has a caching mechanism. Before executing raw SQL directly I would make sure these options (actually many more like avoiding unnecessary joins, as a join operation is resource intensive) are not able to give me what I am looking for. Hope this helps.

肤浅与狂妄 2024-12-19 01:41:23

听起来您正在对数据库进行分区,Sequel 对此有内置支持(http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html)。我建议使用 Sequel,但作为首席开发人员,我有偏见。

It sounds like you are partitioning your database, which Sequel has built-in support for (http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html). I recommend using Sequel, but as the lead developer, I'm biased.

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