Asp.net| Performance | optimization Performance is an important issue for an application, as is the case for web development, believing that no one wants to spend 8 seconds in front of a computer screen waiting for a face to open, which is the 8-second principle that is often said on the web. For the performance of an application, we should consider it as a function of the application, and we should deal with the problem of performance at the time of design, instead of optimizing it after the whole program is developed, because it will pay more price.
Here's a discussion of performance issues in asp.net.
ASP.net improves performance by changing engine changes relative to previous versions of ASP. ASP is a script interpretation engine, there are a lot of code is the runtime to accept user requests compiled, so that many users have the same request will cause the server side of the pressure is heavy, And ASP.net is a compilation of the strategy, only when a page is first requested by the server only through the entire compilation process, which greatly improve the operational efficiency. But the optimization of the engine does not completely solve the asp.net performance problem, and the optimization of the code is another important aspect.
When creating a Web application with asp.net, you should use a three-tier structure model, and three layers are a popular model in recent years. The three layers of the three-tier structure are the presentation layer (the page that the user can see), the Business layer (implementing the business function of the application, commonly called the component, the. dll control compiled from files such as. vb or. cs), the data layer (mainly involves accessing the database with Ado.net). The three-tier architecture enables programs to have better scalability, flexibility, security, platform independence, and maintainability.
asp.net can write logical code using C # or vb.net these object-oriented high-level languages, and when we use these languages to define variables, we need to explicitly define the types of all the variables, avoid the use of late-bound methods of type object, should be bound early, and early binding facilitates code execution to improve performance. We can add explicit= "true" to the page instruction, such as: <%@ Page language= "VB" explicit= "true"%> so that each time we declare a variable, we should specify the type. You can also add the Strict attribute in the page directive such as: <%@ Page language= "VB" strict= "true"%> to avoid late binding.
ViewState is a new feature of ASP.net. Using ViewState makes it easy to maintain control state during a round trip to the server. However, using ViewState can significantly increase the size of the file and also affect performance. So it is advisable to close the ViewState if it is not a last resort, such as: <%@ Page enableviewstate= "false"%> or the viewstate of a control that is stopped individually. In addition, for the session we should also choose the appropriate way to store, there are three ways: Inproc (stored in the process), StateServer (placed in the state server), database (stored in the databases). In InProc performance is the best, but the scalability is relatively poor, the other two modes of performance is not inproc good, but with good scalability, so we should be based on specific circumstances to choose. If you do not need to use sesion, you should also disable requests such as: <%@ Page enablesession= "false"%> to help with faces. If you just read the session without making changes, you can do this: <%@ Page enablesession= "ReadOnly"%> can also improve performance.
Another important way to improve performance is to use caching technology, which has three caching mechanisms for page caching, fragment caching, and data caching in asp.net. Page caching is to put frequently visited pages into the cache, when the user requests the page again without the need to regenerate the page but directly to the cache to send the page to the client, saving response time, greatly improve performance. The specific approach is to add OutputCache instructions in the page code, such as: <%@ OutputCache duration= "" "varybyparam=" None "%> in the above code Duration refers to the cache time, According to the actual situation of the program set, VaryByParam refers to the contents of the cache according to a parameter to change. For example, there is a page on the function of a query weather, when a user input in Beijing query, the page was cached, and another user immediately query the weather in Shanghai, in order to produce output results or is cached in Beijing such a mistake, VaryByParam played a role, <%@ OutputCache duration= varybyparam= "TextBox1"%> where TextBox1 refers to the ID number of the text box in which the address is entered. Fragment page caching is primarily used to cache content in user controls, to add OutputCache instructions to the page code of a user control, and then to include a user control on the page. In some cases, users will request a lot of the same data, if frequently read this data will waste a lot of time, then you can apply data caching technology to improve performance. You can programmatically cache any object. In ASP.net, it is implemented through the Cachel class. such as: cache["myname"]=myname; myname=cache["MyName"];.
Web development can not be separated from the database, in the operation of the database should try to use stored procedures, so as to eliminate the database round-trip access. When using datasets and DataReader, it should also be noted that if the data that is queried from the database is only displayed on the front end and does not need to be modified, the DataReader should be used because the DataReader performance is better than the dataset.
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