从网站性能的角度来看,DTO 有哪些优点和缺点?

发布于 2024-07-06 04:11:24 字数 91 浏览 7 评论 0原文

从网站性能的角度来看,DTO 有哪些优点和缺点? (我指的是在与 Web 服务器不同的应用程序服务器上访问数据库的情况 - 并且 Web 服务器可以直接访问数据库。)

What are the advantages and disadvantages of DTOs from a website performance perspective? (I'm talking in the case where the database is accessed on a different app server to the web server - and the web server could access the database directly.)

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

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

发布评论

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

评论(1

清风疏影 2024-07-13 04:11:24

DTO 不是性能问题。 我认为您要问的是分层对性能的影响。 特别是,在 Web 层(Web 服务器)和数据层(数据库服务器)之间使用应用程序层。

一般来说,这意味着延迟会增加(您有额外的网络往返次数),但您可以通过在计算机之间分配负载来获得一些额外的容量。

人们这样做的另一个常见原因(同样是非性能)是允许他们将 Web 服务器放置在 DMZ 中,同时将应用程序和数据库服务器保留在防火墙内。

另一个潜在原因(非性能)是能够在单个应用程序之上插入多个 UI。 我在过去的项目中做到了这一点,并取得了很好的成果(在业务需要的情况下)。

另外,不要低估维护这种性质的架构所需的工作。 它比非分层解决方案需要更多工作,因此仅在您预计需要时才使用它。

话虽如此,使用 DTO 并不一定需要使用分层。

我发现的关于分层的最佳描述来自 Martin Fowler 的书《分析模式》。 后面有一小部分介绍应用程序外观和分层。

重申一下之前的答案,DTO 不是性能问题。 它只是一个没有用于在应用程序的各个部分之间提供隔离的方法的类。

我还建议阅读 Martin 的另一本书《企业应用程序架构模式》。 DTO“模式”记录在那里。

DTO's aren't a performance concern. I think what you are asking about is the performance implications of tiering. In particular, using an application tier between your web tier (web server) and data tier (database server).

Generally, the implications are that latency is increased (you have extra network roundtrips), but you gain some additional capacity by splitting the load across machines.

Another common reason (again, non-performance) that people would do that is to allow them to place the web server in the DMZ while keeping the application and database servers inside the firewall.

Another potential reason (non-performance) is the ability to plug multiple UIs on top of a single application. I've done this on past projects with great results (where the business required it).

Also, don't underestimate the work required to maintain an architecture of that nature. It's more work than a non-tiered solution, so only use it if you anticipate needing it.

That being said, the use of DTOs does not necessitate the use of Tiering.

The best description I've found of tiering comes from Martin Fowler's book, Analysis Patterns. There's a small section in the back on application facades and tiering.

Just to reiterate the previous answer, DTOs aren't a performance concern. It's just a class without methods used to provide isolation between various parts of your application.

I'd also suggest picking up Martin's other book, Patterns of Enterprise Application Architecture. The DTO "pattern" is documented there.

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