Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize ASP.NET configuration

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to optimize ASP.NET configuration". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to optimize ASP.NET configuration.

State Management of ASP.NET performance Optimization

A) disable session state when it is not in use

Not all applications or pages require the session state of a specific user; you should disable session state when you don't need it. To disable the session state of a page, set the EnableSessionState property in the @ Page directive to false.

If the page needs to access session variables but does not create or modify them, set the EnableSessionState property in the @ Page directive to ReadOnly.

To disable the session state of an application, set the Mode property to Off in the SessionState section of the application's Web.config file.

B) Select the appropriate session state provider for the needs of the application

ASP.NET provides several ways to store application session data: in-process session state, out-of-process session state as a Windows service, and out-of-process session state in the SQL Server database. (you can also create a custom session state provider to store session data in the selected datastore. Each approach has its own advantages, but in-process session state is by far the fastest solution If only a small amount of volatile data is stored in session state, it is recommended that you use an in-process provider. The out-of-process session state option is used to scale applications across multiple processors or computers, or if you want to retain session data when the server or process is restarted.

Web applications with ASP.NET performance optimization

A) consider pre-compilation

In * requests for resources such as ASP.NET Web pages, Web applications are compiled in batches. If none of the pages in the application are compiled, batch compilation compiles all pages in the catalog in batches to increase disk and memory usage. You can precompile Web applications using the ASP.NET compilation tool (Aspnet_compiler.exe). For in-place compilation, the compilation tool calls the ASP.NET runtime to compile the site in the same way that a user requests a page from a Web site. You can precompile a Web application to preserve UI tags, or you can precompile pages so that the source code cannot be changed.

B) remove client dual connection restrictions

The HTTP specification indicates that a HTTP client and any server can establish up to two TCP connections at the same time. This prevents a single browser from overloading the server due to too many connection requests when browsing a page (for example, with 120 embedded thumbnails).

< system.net>

< connectionManager>

< add address="*" maxconnection = "40" />

...

(it will speed up the client's access to the page, but at the same time increase the server load, and the configuration needs to be weighed.)

C) on Internet Information Services 5.0, run the Web application out of process

By default, ASP.NET on IIS 5.0uses out-of-process worker processes to service requests. This feature has been optimized to improve throughput. Because running ASP.NET in an out-of-process worker process has its features and advantages, it is recommended that you use it on the production site.

D) regular recycling process

In order to ensure both stability and performance, the process should be recycled on a regular basis. Over a long period of time, resources with memory leaks and Bug can affect the throughput of Web servers, and the recycling process can clean up memory to avoid such problems. However, the need for periodic recycling should be balanced with excessive recycling, as the cost of stopping worker processes, reloading pages, and refetching resources and data may outweigh the benefits of recycling.

ASP.NET Web applications running on Windows Server 2003 using IIS 6.0do not need to adjust the process model settings because ASP.NET will use IIS 6.0process model settings.

E) adjust the number of threads per worker process of the application if necessary.

ASP.NET 's request structure attempts to strike a balance between the number of threads executing the request and the resources available. The structure will determine the number of requests allowed to be executed concurrently based on the CPU power available for requests. This technique is called thread gating. But under some conditions, the thread gating algorithm is not very effective. Thread gating can be monitored in the ASP.NET Applications performance Monitor by using the Pipeline Instance Count (Pipeline instance count) performance counter associated with the Windows performance object.

When an ASP.NET Web page invokes an external resource, such as performing a database access or XML Web services request, the page request usually stops and releases the CPU to process other threads until the external resource responds. If another request is waiting to be processed and a thread is released in the thread pool, the waiting request begins to be processed. This can result in a large number of simultaneous requests and many waiting threads in the ASP.NET worker process or application pool, which can affect the throughput of the Web server and adversely affect performance.

To alleviate this situation, you can manually set the limit on the number of threads in the process by changing the MaxWorkerThreads and MaxIOThreads properties in the processModel section of the Machine.config file.

Worker threads are used to process ASP.NET requests, while IO threads are used to serve data from files, databases, or XML Web services.

The value assigned to the process model property is the number of threads of each type per CPU in the process. For dual-processor computers, the number of * * is twice the set value. For a four-processor computer, the * value is four times the set value. For computers with one or two processors, the default is fine, but for the performance of computers with more than two processors, having 100 or 200 threads in the process does more harm than good. Because the extra context exchange causes the operating system to spend CPU cycles on maintaining threads rather than processing requests, too many threads in the process tend to slow down the server. The appropriate number of threads is determined by performance testing of the application.

F) disable debug mode

Always disable debug mode before deploying a production application or making any performance measurements. If debug mode is enabled, application performance may be affected.

< system.web>

< compilation debug="false">

...

G) optimize the configuration files of Web server computers and specific applications to meet your needs

By default, the ASP.NET configuration is set to enable the broadest feature set and adapt to the most common situations as much as possible. You can change some default configuration settings to improve the performance of your application, depending on the features you use.

1) enable authentication only for required applications

By default, the authentication mode for ASP.NET applications is Windows or integrated NTLM. In most cases, * disables authentication in the Machine.config file and enables authentication in the Web.config file only for applications that require authentication.

2) configure the application according to the appropriate request and response coding settings

The default encoding format of ASP.NET is UTF-8. If your application uses only ASCII characters, configure your ASCII application for a slight performance improvement.

3) consider disabling AutoEventWireup for the application

Setting the AutoEventWireup property to false in the Machine.config file means that the page does not bind page events to methods based on name matching (such as Page_Load). If you disable AutoEventWireup, the page will get a slight performance improvement by leaving the event connection to you instead of automatically executing it.

If you want to handle page events, you can use one of two strategies. The strategy is to override the methods in the base class. For example, instead of using the Page_Load method, you can override the OnLoad method of the Page object for the page load event. Be sure to call the base method to ensure that all events are raised. The second strategy is to use the Handles keyword in Visual Basic or the delegate connection in C # to bind to the event.

4) remove unused modules from the request processing pipeline

By default, all functions of the HttpModules node in the Machine.config file of the server computer remain active. Depending on the functionality used by your application, you can remove unused modules from the request pipeline to get a slight performance improvement. Examine each module and its functions and customize it to suit your needs. For example, if you do not use session state and output caching in your application, you can remove them from the HttpModules list so that you do not have to call these modules when no other meaningful processing is performed.

Thank you for reading, the above is the content of "how to optimize ASP.NET configuration". After the study of this article, I believe you have a deeper understanding of how to optimize ASP.NET configuration, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report