什么时候应该使用 ORM 主义,什么时候应该使用 zend-db-table?
就项目规模、doctrine 与 zend-db-table 的速度和性能而言,我什么时候应该在 Zend 项目中使用doctrine,什么时候应该使用 zend-db-table?
In terms of project scale, doctrine vs zend-db-table speed and performance, when should I use doctrine inside Zend project, and when zend-db-table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
任何 ORM 框架都能为您带来开发效率的好处,而不是运行时效率。在这方面,Doctrine 与 Zend_Db_Table 没有什么不同。
如果您在 Doctrine 和 Zend_Db_Table 之间进行选择,请根据使编写代码更容易或更快的功能进行选择。
在一般情况下,没有任何 ORM 框架可以自动使数据库查询更快。如果您需要高性能数据库查询,您应该学习编写 SQL 查询代码,并设计架构和索引以支持给定您需要运行的查询的性能。
Any ORM framework gives you benefit for development productivity, not runtime efficiency. Doctrine is no different from Zend_Db_Table in this regard.
If you are choosing between Doctrine and Zend_Db_Table, choose based on the features that make it easier or faster to write the code.
No ORM framework can automatically make database queries faster in the general case. If you need high-performance database queries, you should learn to code SQL queries, and design your schema and indexes to support performance given the queries you need to run.
使用你最舒服的任何东西,会让你变得最有效率。您和您的开发人员同事可能是最昂贵的资源,如果需要的话,购买额外的硬件可能比您担心未来可能的性能考虑更便宜。
当然,您仍然需要执行基本的数据库优化,例如创建合理的索引等。但我觉得这些“优化”是不言而喻的。
Use whatever you are most comfortable with and will make you the most efficient. You and your fellow developers are probably the most expensive resource, and it's probably cheaper to buy additional hardware, if needed, than you having to worry about possible future performance considerations.
Of course, you will still need to perform basic database optimizations such as creating sensible indexes etc. But I feel that those "optimizations" go without saying.
如果您有大量 SQL 查询,并且缺乏知识(对缓存或查询优化等一无所知)并且缺乏时间,请使用 Zend_DB,它更快、更容易理解,并且对您来说足够好 - 那个缺乏知识和时间,想要尽可能快。
但如果你想要杀手级的 ORM 学说获胜。但需要更多的时间和精力才能有效利用。
如果你想成为数据库杀手,我们就偏离主题了。这是不同的。它不一定取决于您使用的工具。 (一些 DB 杀手可能使用 PDO 本身和他们自己的模型,谁知道呢?)
if you have a lot of SQL queries, and lack of knowledge (knowing nothing about caching or query optimization, etc.) and lack of time use Zend_DB it is faster and easier to be understood and it is good enough for YOU - the one who is in lack of knowledge and time and want to be as fast as possible.
but if you wanna a killer ORM doctrine wins. but it requires more time and energy to be used efficiently.
and if you wanna be a DB killer, we're gonna go off topic. it is different. and it is not necessarily based on what tools you use. (some DB killers probably use PDO itself and their own models, who knows?)
Doctrine 可以帮助你定义更好的业务逻辑和 ORM,但就内存和 CPU 而言,它绝对是性能杀手。
Zend 表网关比 Doctrine 快 5 倍。您可以扩展 Zend 表网关来删除某些数据类型解析器,这将使您的性能提高 5 倍,同时仍然保留简单 ORM 的优势。这是我的 FastTablegateway 类:
Doctrine helps you define a better business logic and ORM, but it is an absolute performance killer in term of memory and CPU.
Zend table gateway is 5x times faster than Doctrine. And you can extend Zend table gateway to remove some data type parser and that will give you an improvement of 5x more preserving still the benefit of and simple ORM. Here is my FastTablegateway class: