现在N层架构意味着什么?
从传统意义上讲,N 层意味着将应用程序分成“层”,并将每个“层”放在不同的服务器上。这样做至少有 3 个原因:
维护:
a) 代码维护:更容易修复错误和添加功能。
b) 硬件维护:关闭一台服务器不会中断其他层的服务。
性能:一台服务器通常不够快,无法同时处理 Web 请求、业务逻辑计算和数据库/文件访问。
可扩展性:特别是水平可扩展性
a) 容错能力:每层能够拥有超过 1 台物理服务器,这意味着当 1 台服务器出现故障时,应用程序仍然可以作为一个整体运行。
b) 负载平衡:拥有一个层的多个实例有助于为大量请求提供服务。
如今,硬件和网络的速度足以在单个服务器上每秒处理数千个请求。此外,现在 IT 的流行词是“整合”。因此,即使应用程序被分成几层,它们最终也可能会托管在单个服务器上的虚拟机上。
我认为现在当人们谈论 N 层架构时,他们谈论的是应用程序内的关注点分离。它更多的是一种逻辑分离,而不是物理分离。我认为只要我们实现良好的关注点分离和松散耦合,应用程序就不必是N层的。似乎许多程序员认为 N 层架构是每个 Web 应用程序都必须遵守的黄金标准。
那么,现在的 N 层架构对您来说是什么?
In a traditional sense, N-tier means separating the application into "tiers" and putting each "tier" on different servers. This was done for at least 3 reasons:
Maintenance:
a) Code Maintenance: Easier to do bug fixes and feature additions.
b) Hardware Maintenance: Taking one server down does not disrupt service from other tier.
Performance: One server was often not fast enough to handle web requests, business logic computations, and database/file access at the same time.
Scalability: Specifically horizontal scalability
a) Fault Tolerance: Ability to have more than 1 physical server per tier means when 1 server is down, the application can still function as a whole.
b) Load-balancing: Having multiple instances of a tier helps service large amount of requests.
Nowadays, hardware and networks are fast enough to serve thousands of requests per second on a single server. Also, the buzz word for IT right now is "consolidation". So even if the application is split into tiers, they probably will end up hosting on virtual machines on a single server.
I think nowadays when people talk about N-tier architecture, they are talking about separation of concerns within the application. It is more of a logic separation than a physical one. I think as long as we achieve good separation of concerns and loose coupling, applications do not have to be N-tier. It just seems that many programmers think that N-tier architecture is a golden standard that every web application must comply with.
So, what is N-tier architecture to you nowadays?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从维基百科文章我读到:
我确实认为“层”的概念和“层”的概念随着时间的推移而混淆了。
我个人喜欢只谈论层而不是层,因为我更喜欢 PAAS 解决方案,我只关心软件,而且行业正在慢慢朝这个方向发展。
另外,当您计划一个可以极大扩展的应用程序时,我仍然认为您不应该考虑 n 层的可扩展性。
事实上,非常受欢迎、流量很大的网站只分为 3 个部分:
数据库服务器、Web 服务器(包括缓存服务器)和一些 CDN(内容分发网络)。
这种分离可以在任何应用中实现。
但总而言之,我认为程序员应该只考虑应用程序中的层和关注点分离,以实现最重要(也是最困难)的任务:从长远来看可维护性。
From wikipedia article I read:
I do think that the concept of "layer" and the concept of "tier" got mixed up with time.
I personally like to talk about layers only rather than tiers as I prefer PAAS solutions where my concerns are only on the software, and the industry is slowly moving in this direction.
Also when you plan for an application that could greatly expand I still don't think that you should think about n-tier for scalability.
In fact, very popular websites with a lot of traffic only separate themselves into 3 components:
Database servers, web servers (including the caching servers), and a few CDN (content delivery networks).
This kind of separation can be achieved in any application.
But to conclude, I think a programmer should only think abuot layers and separation of concerns within the application to achieve the most important (and difficult) task: maintainability in the long run.
一个人的安全?我宁愿你访问我的网络服务器而不是我的应用程序服务器!
Security for one? I'd rather you hit my web servers than my app servers!
我认为这是而且一直都是人为的区别。我同意你的前提,即现在它主要指的是组件的逻辑分离。然而,仍然有很多应用程序太大(使用方面或数据方面)而无法安装在一台机器上,因此出于可扩展性原因将应用程序分离为离散组件的想法绝对不会消亡。
I think it is, and always has been, an artificial distinction. I agree with your premise that it refers mostly to logical separation of components these days. However, there are still plenty of applications that are too big (use wise or data-wise) to fit on a single machine, so the idea of separating an application into discrete components for scalability reasons is definitely not dead.