使用单个 mysql 数据库对多个 Rails 应用程序进行内容管理
我打算创建多个具有类似功能的 Rails 博客应用程序。 为了减少管理这些 Rails 应用程序所花费的时间,我决定创建一个单一的内容管理系统来监督它们。例如。 content.example.com
在此 CMS 的设计中,我一直在争论是否使用包含所有博客应用程序数据的单个 mysql 数据库。这个单一数据库将位于 CMS 应用程序(“content.example.com”)上,其他应用程序随后将查询其数据。
博客应用程序:
//model Blog.rb
class Blog < ActiveRecord::Base
establish_connection "external_cms"
end
//database.yml
external_cms:
adapter: mysql
database: root/to/external/cms_db
username: user
password: password
在这种情况下,CMS 应用程序数据库将很快变得非常大,从而减慢博客应用程序的查询速度。即使使用索引,我也知道这可能不是一个可行的选择。我读过一些博客,还需要考虑的是博客应用程序的 schema.rb 和模型需要与 CMS 应用程序的相同。到目前为止,在我的测试中,我发现 schema.rb 根本不必相同(尚未测试模型是否需要相同)。
在同一个数据库上运行多个应用程序是常见的做法吗?如果不是,是否是因为查询速度变慢以及需要保持 schema.rb 和模型相同而带来的麻烦?
除了索引之外,还有哪些其他方法可以加快查询速度以弥补大型数据库的不足?
除了运行单个数据库同时保留一个 CMS 之外,我还有哪些替代方案?
I intend to create multiple rails blogging applications with similar functionalities.
To cut down on time spent managing these rails applications I have decided to create a single content management system to oversee them all. eg. content.example.com
In the design of this CMS i have been debating whether to use a single mysql database containing the data for all of the blogging apps. This singular database would be on the CMS app ("content.example.com"), which the other applications would then query for their data.
Blogging App:
//model Blog.rb
class Blog < ActiveRecord::Base
establish_connection "external_cms"
end
//database.yml
external_cms:
adapter: mysql
database: root/to/external/cms_db
username: user
password: password
In this scenario the CMS apps database would become very large quickly, slowing down the queries from the blogging apps. Even with Indexing i'm aware that this might not be a viable option. I've read on a few blogs also to consider is that the schema.rb and models of the blogging apps would need to be identical to that of the CMS app. In my testing so far ive found that schema.rb does not have to be the same at all (have not tested whether models need to be identical).
Is it common practice to run multiple apps off the same database? And if not is it becuase of the slowing on queries and the headaches associated with needing to keep schema.rb and models identical?
As well as indexing what are other ways in which i can speed up the queries to compensate for a large database?
what are my alternatives to running a single database whilst keeping the one CMS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题经常出现,您最好阅读多租户以及它是否有意义为你。
我的建议是从使用相同数据库的所有博客应用程序开始,然后在性能成为问题时进行分片(这可能永远不会)。
有很多方法可以加快数据库访问速度,第一道防线是缓存。
This question pops often, it's best for you to read up on multitenancy and whether or not it makes sense for you.
My advice is start with all your blogging apps using the same database and then shard when performance becomes a problem (which it might never).
There are many ways to speed up database access, with the first line of defense being caching.