RedBean ORM表现 [英] RedBean ORM performance

查看:184
本文介绍了RedBean ORM表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,Redbean ORM可以用于面向性能的场景,如社交网络应用程序,即使数以千计的数据同时被多个用户拉出来,它是否稳定?另外我想知道Redbean是否消耗更多的内存空间?



任何人都可以提供Doctrine-Propel-Redbean的比较研究?

解决方案


@tereško如果可能,你可以根据你的经验给出纯粹的sql的优点和缺点,还有我会同时google这个话题。 - Jaison Justus


嗯..解释这个600个字符将是困难的。



有一点我必须澄清:这是关于 PHP 中的ORM,虽然我很确定它适用于一些Ruby ORM,也可能是其他。



简而言之,你应该避免他们,但如果你必须使用ORM,那么你会更好地使用Doctrine 2.x,这是较小的邪恶。 (实现类似于 DataMapper 而不是ActiveRecord的内容)。



针对ORM的案例



一些开发人员喜欢使用ORM的主要原因也是他们最糟糕的事情:很容易做到ORM中简单的事情,性能成本非常低。这是非常好的。



1。指数复杂性



问题源自于所有人都使用相同的工具。 如果你所有的都是锤子(..)类型的问题。这将导致创建一个技术债务



首先很容易写出新的DB相关代码。也许,因为你有一个大项目,管理在第一周(因为后来会出现额外的问题 - 读神话人月,如果对细节感兴趣)决定雇用更多的人。而您最终宁愿拥有ORM技能的一般SQL。



但是,随着项目进展,您将开始使用ORM来解决日益复杂的问题。您将开始劫持一些限制,最终您可能会遇到一些问题,即使您知道的所有ORM黑客也无法解决,现在您没有SQL专家,因为您没有雇用他们。 / p>

此外,大多数受欢迎的ORM正在实施 ActiveRecord ,这意味着您的应用程序的业务逻辑直接耦合到ORM。由于这种耦合,添加新功能将需要越来越多的时间。出于同样的原因,很难为他们编写良好的单元测试。



2。性能



我已经提到甚至使用ORM(使用单表,没有 JOIN )有一些性能成本。这是因为他们使用通配符 * 来选择数据。当您只需要文章ID和标题列表时,无需提取内容。



当您需要数据时,ORM在处理多个表时真的很糟糕基于多个条件。考虑问题:


数据库包含4个表:项目演示文稿幻灯片 Bulletpoints




  • 项目有许多演示文稿

  • 演示文稿有许多幻灯片

  • 幻灯片有很多Bulletpoitns



您需要从所有 Bulletpoints 相关的幻灯片标签为重要的c> c> c 与ids 2,4和8。


这是一个简单的JOIN来写纯SQL,但是在任何ORM实现中,我已经看到,这将导致3级嵌套循环,每级都有查询。






PS 还有其他原因和副作用,但它们相对较小..现在不记得任何其他重要问题。


I would like to know, can Redbean ORM be used for performance oriented scenarios like social networking web apps, and is it stable even if thousands of data is pulled by multiple users at same time? Also I'd like to know whether Redbean consumes more memory space?

Can anyone offer a comparison study of Doctrine-Propel-Redbean?

解决方案

@tereško if tis possible, can you give the pros and cons of orm with respect to pure sql according to your experience and also i will google the topic at same time. – Jaison Justus

Well .. explaining this in 600 characters would be hard.

One thing I must clarify: this is about ORMs in PHP, though i am pretty sure it applies to some Ruby ORMs too and maybe others.

In brief, you should avoid them, but if you have to use an ORM, then you will be better of with Doctrine 2.x , it's the lesser evil. (Implements something similar to DataMapper instead of ActiveRecord).

Case against ORMs

The main reason why some developers like to use ORMs is also the worst thing about them: it is easy to do simple thing in ORM, with very minor performance costs. This is perfectly fine.

1. Exponential complexity

The problem originates in people to same tool for everything. If all you have is a hammer (..) type of issue. This results in creating a technical debt.

At first it is easy to write new DB related code. And maybe, because you have a large project, management in first weeks (because later it would case additional issues - read The Mythical Man-Month, if interested in details) decides to hire more people. And you end up preferring people with ORM skills over general SQL.

But, as project progresses, you will begin to use ORM for solving increasingly complex problems. You will start to hack around some limitations and eventually you may end up with problems which just cannot be solved even with all the ORM hacks you know ... and now you do not have the SQL experts, because you did not hire them.

Additionally most of popular ORMs are implementing ActiveRecord, which means that your application's business logic is directly coupled to ORM. And adding new features will take more and more time because of that coupling. And for the same reason, it is extremely hard to write good unit-tests for them.

2. Performance

I already mentioned that even simple uses of ORM (working with single table, no JOIN) have some performance costs. It is due to the fact that they use wildcard * for selecting data. When you need just the list of article IDs and titles, there is no point on fetching the content.

ORMs are really bad at working with multiple tables, when you need data based on multiple conditions. Consider the problem:

Database contains 4 tables: Projects, Presentations, Slides and Bulletpoints.

  • Projects have many Presentations
  • Presentations have many Slides
  • Slides have many Bulletpoitns

And you need to find content from all the Bulletpoints in the Slides tagged as "important" from 4 latest Presentations related to the Projects with ids 2, 4 and 8.

This is a simple JOIN to write in pure SQL, but in any ORM implementation, that i have seen, this will result in 3-level nested loop, with queries at every level.


P.S. there are other reasons and side-effects, but they are relatively minor .. cannot remember any other important issues right now.

这篇关于RedBean ORM表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆