From the perspective of MVC and three-tier architecture, optimizing architecture and improving web Efficiency

Source: Internet
Author: User
The MVC was shot last time, and the three-tier architecture was shot again this time. I felt like a Red Guard with a big text everywhere ^_^, but I cannot tell it clearly, I hope my bricks will attract more incisive explanations.
Speaking of the layer-3 architecture, MVC is actually caused by seeing a man show me his outline design book, because this gentleman can represent many beginners developers and misunderstandings he has experienced, many developers may experience it (including myself, who did a lot of silly things in the past ). From the historical point of view, there is no intersection between MVC and hierarchical design. Many people often think that this is the best way, so they will confuse the two concepts, so a Jun's profile design book is written like this:
... This system is a typical three-layer architecture design. It adopts the MVC pattern ......
This is not to say that Layer 3 is not good or MVC is not good, but at least we need to first figure out what Layer 3 is and what MVC is to say whether the two can be combined or how to combine them, but in this ORM (in fact, Orm is also a concept, whether you are Code The significance of Layer 3 has been deprecated. First, let's take a look at the concept of a layer-3 architecture. Generally, the three layers are the presentation layer, business logic layer, and data operation layer. There is a vertical relationship between the layers. In other words, the call stack is very thick. It is actually borrowed from the concept of network layering. Each layer of the network is a protocol stack. There is a weak coupling between the upper-layer protocol and the lower-Layer Protocol because of the stability of the interface between the layers. The upper-layer protocol does not care about what the underlying protocol is. So Program The layer-3 architecture is designed to achieve weak coupling. For pages, the business logic is transparent. For business logic, the details of data operations are transparent, then different programmers can implement it separately. So, it seems to be a good pie, but the problem is also very simple, long call stack, lower efficiency, and complicated expansion, we need to re-compile and deploy the DLL and site of the entire business logic layer for each extended function. However, in this case, the application scope is required. In many cases, the website logic is quite simple, read the table and fill the grid. This logic must be run once in the business logic. In fact, there is only one line or several lines of code in the Protocol method, which is actually the result of forwarding the data layer. To be honest, if we were a news publishing system, almost all of the business logic layer would be forwarded code. As a result, when we modified the database, we had to change a few more places. It was almost impossible to find anything. Another case is that the stored procedure is used in large quantities, and the logic is in the stored procedure. As a result, the business logic layer is useless and completely becomes a sound transmitter. Some people say that we can verify the data here. It seems that this is the case. If you want to write a layer of film, The man knows that the multilayer film is uncomfortable. Why do you need to use it?
Let's take a look at MVC. Although MVC (MVP) was shot last time, MVC is much more cute than a thousand-layer cake. At least it is more in line with the actual situation. For the web, the score layer is more reasonable. MVC is a typical parallel relationship. It does not mean the relationship between the top and bottom, and the model is responsible for the business field, the view is responsible for the display. The controller reads the data and fills the model, and then submits the model to the view for processing. Various verifications should be handled in the model. A slight modification on the Web is also quite natural. Many people mix MVC and multiple layers for use, and it is easy to be tall and nondescribable without knowing clearly. In fact, this is not important, mainly because the efficiency and flexibility are reduced, that is a fatal problem.
There are many factors related to the efficiency of Web application execution. Here we only look at the impact of architecture changes on database operations.
One is multi-layer, with each business object having its own data connection. What are the consequences? On one page, the database connection is closed N times in turn, these are all consumption-consuming, and the Web is not used by a user. There are 10 connections to a page, at the same time, 1000 accesses will cause 10000 database connections to be closed in a short period of time. There is also a trend of single database connections (a man mentioned in the post http://www.cnblogs.com/ayuan/archive/2007/03/24/686594.html, but it seems that the man put the concept of IIS connection limit is wrong, I will remind him later ). In fact, this is also not desirable. This will cause a serious reduction in the efficiency of multi-user access, because there is always only one connection, and the queue will be suspended frequently when many people request it, the loss is not worth the candle. In fact, when we carefully analyze the Web working mode, we will find that, first of all, for the entire web application, it is a multi-threaded environment, each session has a working thread to handle, every thread is isolated, and only the application is the public zone between threads (so even ASP provides the lock and unlock mechanisms for the application, why? Thread Security), but the static part of our code is for each session, so in this regard, our program can be seen as a single thread (except for application and static-related code ). In fact, we need to have a connection for each session to achieve the goal of optimizing the connection resources, but many times this will sacrifice the structure of the entire site, and there is another problem here, if an opened connection is stored in the session, the connection cannot be closed if the user's session is not recycled. In this case, 50 users will occupy 50 connections, in general, the number of sqlserver connections is limited, so it is not a slow issue. When users come in, there will be no connection available, so I prefer to put a connection on each page, when the page is opened during initialization and closed at the end of the execution page, the efficiency is basically optimized. As for business logic, I tend to be parallel, as a series of logic helper classes, which only process domain models (mvc m, entity class or dataset), data operations are still in the controler. What should I do if I want to change the database? Now daab3.1 and n many ORM support multiple databases, so you don't have to worry about it here.

Continue to advertise your components:
Http://www.cnblogs.com/Alexander-Lee/archive/2007/03/30/694049.html with cache Oh, BA is very well oh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.