ORM 性能成本 [英] ORM performance cost

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

问题描述

有没有人有任何经验表明,通过选择使用 ORM(在 Django、RoR、SQLAlechemy 等中)而不是 SQL 和手工设计的数据库,开发人员可以期望获得什么样的性能?我想有一些复杂的问题,包括在 ORM 的约束内指定数据库是否会增加或减少创建有效数据库结构的机会(基于开发人员的经验水平),以及开发人员构建基于 SQL 或 ORM 的查询(同样基于他/她的经验).关于这些或内在性能问题的任何信息对我来说都非常有趣.

Does anyone have any experience that indicates what kind of performance hit a developer could expect by choosing to use an ORM (in Django, RoR, SQLAlechemy, etc) over SQL and hand-designed databases? I imagine there are complicating issues, including whether specifying a database within the constraints of an ORM increases or decreases the chances of creating an efficient database structure (based on the developer's level of experience), and the question of how well the developer constructs either the SQL or ORM-based queries (again based on his/her experience). Any information regarding these or intrinsic performance issues would be really interesting to me.

推荐答案

我的建议是不要担心这个,除非你需要 - 不要过早地优化.ORM 可以为开发速度、代码可读性提供许多好处,并且可以消除大量代码重复.如果它能让您的应用程序更易于开发,我会建议使用它.

My advice is not to worry about this until you need to - don't optimise prematurely. An ORM can provide many benefits to development speed, code readability and can remove a lot of code repetition. I would recommend using one if it will make your application easier to develop.

随着您在开发过程中的进展,使用基准测试和分析来确定代码中的瓶颈,如果需要,您可以绕过 ORM 并在需要时使用手动查询.通常,您将能够使用缓存和数据库索引(除其他外)来提高 ORM 的速度,然后您可以决定需要手动查询的位置.在大多数情况下,ORM 性能可能是可以接受的,使用它的好处将远远超过性能成本.

As you progress through the development use benchmarks and profiling to determine the bottlenecks in the code and if needed you can bypass the ORM and use manual queries where they are required. Normally you will be able to improve the speed of the ORM using caching and database indexes (amongst other things) and then you can decide where manual queries are required. For the most part, the ORM performance will probably acceptable and the benefits of using it will far outweigh the performance cost.

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

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