Asp. NET performance optimization

Source: Internet
Author: User
Tags sql injection client
Asp.net| Performance | optimization
Ways to measure Web performance



• The only way to measure Web server performance is to stress test the server (stress testing)



1. Automatic pressure test tool is the only way to measure



2. The click refresh of the browser cannot be used as a trace measure ...







• Collect multiple typical scenario scenarios:



1. The process of simulating typical things during the execution of the application of the lathe son-in-law



2. The performance of a single page of trace usage (hot)



3. Determine the use of a scene and a page







• Identify new energy indicators for the system by testing:



1. Server processing capacity



2. Determine the maximum client load that is appropriate for acceptable ttfb/ttlb response time ranges (concurrent users)











Performance testing Tools



L Microsoft Web application Stress Tool



1. Available for free download (10MB), for XP, 2000, 2003



2. http://www.microsoft.com/technet/treeview/default.aspx?url=/technet/itsolutions/intranet/downloads/webstres.asp







• Microsoft Application Center testing tool (Microsoft Application Center Test)



1. Provided to customers as part of Vs.net Enterprise



2. Enable richer scripts and reports











Main performance test observations perfmon counters



L PROCESSOR,CPU% Utilization



Low numbers = Blocking or lock contention







L asp.net,requests in Application Queue



Indicates that the server has reached full load when linear growth occurs







L ASP.NET,APPLICATIONS,REQUESTS/SEC



Dynamic throughput (should be consistent, no large fluctuations)







L Asp.net,applications,errors Total



Indicates a functional level error (should be 0)







L asp.net app/worker Process restarts



Indicates a critical error programming level error (should be 0)



Stress test Environment considerations



L Run the Stress test tool on the standalone and Web server and application server machines



1. Otherwise the tool will exceed the maximum server CPU range



2. Use multiple client machines for heavy load







• Configure tests to simulate different client bandwidth levels



1. Specific for measuring 56K dialing







L eliminate any bottle manipulate outside the application:



1. Network, client, etc.











Logical design



Recommendation: Using the 3-tier logic model



1. Pages and User Controls UI



2. Business and Data Access classes in \ bin Dir



3. Data Withwin a SQL Database via SPROCs







L Design the system to take into account the scale-out situation



1. Do not assume that client requests







L will always return to the same machine











Using the best data Provider



L Ado.net can support multiple provider:



1. System.Data.SqlClient



2. System.Data.OracleClient



3. System.Data.OleDb



4. System.Data.Odbc







L All provider programming models are the same



1. But there are significant differences in performance







L Recommend: Use the best



1. In Access Msde/sql is always used SqlClient



2. Always use OracleClient when visiting Oracle



















DataReader vs. Datasets



L DataReader



1. Provides a one-way read operation for the results of a query



2. Lightweight fast-but the database is always connected until reader closes







L DataSet



1. Non-connected data access methods



2. Internal use of DataReader users to obtain data



3. Automatically closes DataReader after completion of DataSet acquisition







L Which is better?



1. Depending on your application



2. In principle, the dataset is recommended for middle_tier design to large amounts of data processing or off-line data access











Connection pool



L ADO. NET has a built-in connection late



1. Automatic Slow/reuse connection



2. You don't have to write any code for this







L Code Suggestions



1. "Connect in late-opening code, then close it early"



2. No long time to stay connected-no attempt to build your own "smart" connection pool logic



3. Close the database connection immediately after it is completed to return it to the pool







L Optimization Tips:



1. Different connection strings can generate a number of different connection pools



2. Store a single connection string in Web.config



3. Use ConfigurationSettings.AppSettings to access it programmatically at run time



4. Observe the ". NET CLR Data" performance counters to change the number of connection pools maintained by Adp.net











Using Stored Procedures



L recommend the use of SPROC for data access



1. Easier performance Tuning via DBA



2. Avoid distributed transaction costs by using database transactions



3. Helps prevent SQL injection attacks



4. Help and eliminate the cost of application and database repeated calls















Server control



L There are two points to be aware of for performance optimization:



1. ViewState



2. Number of controls generated (especially for lists)











ViewState management



L asp.net controls is able to maintain the state of the page control element:



1. The state is passed in "ViewState" hidden field







L Negative Impact:



1. Increase Network Load (both on render and postback)



2. Additional server performance consumption (Serialize values To/from viewstate)







L ViewState Flexibility:



1. Page level (Can disable viewstate entirely for a page)



2. Control level (Can disable ViewState usage on a/per controls basis)







L suggest



1. Carefully review the use of this function



2. If you do not use the postback function, at the page level screen viewstate



3. Postback the control at all times, disable the control-level viewstate



4.%> tracking ViewState size using <%@ Page trace= "true"




Related Article

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.