持续性无知可以规模化吗?

发布于 2024-07-13 19:10:25 字数 156 浏览 8 评论 0原文

我简要了解了 NHibernate 和 Linq2Sql。 我还打算了解一下实体框架。

当我谈论这些 ORM 时,提出的问题是“它们无法扩展”,那么它们可以吗? 从谷歌我得到的印象是他们能够很好地扩展,但最终我认为必须付出代价,是否值得为更丰富、更简单的业务层付出代价。

I've been having a brief look at NHibernate and Linq2Sql. I'm also intending to have a peek at Entity Framework.

The question that gets raised, when I talk of these ORM's is "They can't scale", so can they? From Google I get the impression they're able to scale well, but ultimately I suppose there must be a price to pay, Is it worth paying for a richer simpler business layer.

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

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

发布评论

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

评论(3

待"谢繁草 2024-07-20 19:10:25

这是一个很好的问题,恕我直言,他们可以像任何自定义 DAL 一样进行扩展。 我只使用过 nHibernate,因此我将只关注它以及它具有的有助于扩展系统的功能。

  • 延迟加载 - 由于它支持延迟加载,您可以避免加载任何不必要的项目。 当然,您需要注意 Select n+1 问题,但是系统中有一些东西可以防止这种情况发生。
  • 急切获取 - 有多种方法可以急切获取您可能需要的对象,从而避免额外的 SQL 访问。
  • 二级缓存 - nHibernate 支持二级缓存,可用于通过减少数据库访问来提高可扩展性。 有各种可用的支持提供商,可以为您提供一定的灵活性。
  • 编写您自己的 SQL - 在 nHibernate 中,您可以调用存储过程,或提供将返回您的实体的内联 SQL 查询。 当生成的 sql 无法删除时,这将允许您使用自己的 SQL。 例如,使用递归查询预先加载自连接树。

话虽如此,我认为最初调整自定义 DAL 层会更容易,因为您熟悉它的构造并且可以对其进行微调; 然而,一个好的 ORM 会提供大量的钩子,让你可以进行相当多的优化。 你只需要花一些时间学习它。

我还认为,如果您有性能关键的代码区域,并且无法让 ORM 在您的要求范围内工作,那么对于应用程序的这一小区域,您可以自定义构建自己的 DAL 层。 如果您使用的是不错的设计模式,例如工厂创建的存储库,那么您需要做的就是交换存储库的实现

This is a good question, and IMHO they can scale just as well as any custom DAL. I've only used nHibernate so I will focus only on it and the features it has which can help scale a system.

  • Lazy Loading - Since it supports lazy loading you can avoid loading any unnessecary items. Of course you need to watch out for the Select n+1 problem however there are things in the system to prevent this.
  • Eager Fetching - There are various ways to eagerly fetch objects which you might need allowing you to avoid extra trips to SQL.
  • Second Level Cache - nHibernate has support for a second level cache which can be used to increase the scalability by reducing trips to the DB. There are various backing providers available which give you some flexibility.
  • Write your own SQL - In nHibernate you can call stored procedures, or provide the SQL query inline that will return your entities. This will let you use your own SQL when the generated sql doesn't cut it. For example eager loading a self joining tree using a recursive query.

Now with that said, I think it is easier to initially tweak a custom DAL layer because your are intimate with its construction and can fine tune it; however, a good ORM will provide plenty of hooks that allow you to optimize quite a bit. You just need to spend some time learning it.

I also feel that if you have a performance critical area of code and you can't get your ORM to work within your requirements then for that tiny area of your application you can custom build your own DAL layer. If you're using a decent design pattern such as a Repository created by a factory, then all you need to do is swap out the implementation of your repository

踏雪无痕 2024-07-20 19:10:25

Hibernate Shards 正在移植到 NHibernate,这将允许水平缩放。

还有一些非常酷的黑客,例如 这个来实现分片。

所以答案是肯定的,NHibernate 可以以一种持久性无知且完全透明的方式进行扩展。

Hibernate Shards is being ported to NHibernate, which will allow for horizontal scaling.

There are also some very cool hacks like this one to implement sharding.

So the answer is yes, NHibernate can scale, in a persistance-ignorant and fully-transparent way.

穿越时光隧道 2024-07-20 19:10:25

说在 ORM 中构建的应用程序不能很好地扩展是完全错误的。 当然,以前也曾发生过粗心或懒惰的开发人员通过编写生成极其低效的 SQL 的代码来滥用 ORM 的情况。 构建高性能应用程序意味着了解所有可爱的抽象在幕后的实际用途。 然而,要避开这个陷阱并不需要太多的时间。 使用 ORM 并不意味着永远不要打开 SQL Profiler 或 NHibernate Profiler

关于 SP 速度更快的说法,请阅读此 和这个。 此外,ORM(至少是NHibernate)为您提供了非常简单的方法来使用SP(如果您需要的话)。

It's simply incorrect to say that apps built in an ORM do not scale well. Certainly it has happened before that careless or lazy devs abuse an ORM by writing code that generates horribly inefficient SQL. Building performant apps means understanding something about what all the lovely abstractions actually do under the hood. It does not take much to stay out of this trap however. Using an ORM doesn't mean never opening SQL profiler or NHibernate Profiler.

And regarding the claim that SPs are just a whole lot faster, read this and this. And besides, ORMs (NHibernate, at least) give you pretty easy ways to use SPs if you ever need to.

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