for a website, performance is always a hot topic. How many performance indicators are there?
1: execution time
the time required to process a request, generally, the time between the first byte and the last byte is returned to the client by the server. The execution time directly affects the throughput calculation.
2: response time
after the client initiates a request, the length of time the server returns the first byte to the client. For client users, this is usually the most intuitive aspect of performance.
3: scalability
it is used to measure the application's Program performance when obtaining more resources.
4: throughput
refers to the number of requests that an application can process per unit of time, it is usually measured by the number of requests per second. The Throughput varies depending on the number of client threads on the application server.
When we know a good web website performance indicator, what we desire is to optimize our website. Below I will introduce several common Asp.net application optimization solutions.
1. When we do not need to authenticate the user identity, close the session as much as possible.Session usage will greatly reduce the application performance. If you want to disable Page Sessions, you can set the enablesessionstate attribute in the @ page command to false. If the page needs to access session variables but does not intend to create or modify them, we can set the enablesessionstate attribute in the @ page command to readyonly. Of course, if you are harsh enough, disable the session Status of the entire application. You can set the mode attribute to off in the sessionstate configuration section of the file in the configuration file.
2. Try to use client scripts.As a large number of Asp.net programmers, they do not like to write client scripts on the front end, and they all like to write scripts on the back end.CodeOn the one hand, it is much more comfortable to write code in the background. On the other hand, due to the workload and limited time, it is very rare to write script code in the foreground to complete the task and improve the development efficiency. Therefore, although we may try to use the time-saving and code-saving functions of the web forms page framework as much as possible, it is not suitable to use server-side controls and sending back events in some cases. Generally, the round-trip process to the server should be started only when data is retrieved or stored, and most data operations can be performed on clients during the round-trip process. That is to say, if the data we manipulate is not transferred to the server to store it in the database, we should not write the code that leads to the round-trip process.
3. Use Page. ispostback to avoid unnecessary operations on the round-trip process.This is because. The code of the page_load event is executed before the Server Control event is executed. In general, the first time we load the page, we execute a piece of code, the code for sending back the server control does not need to process the code. It processes the B code. At this time, we can use the page based on whether the page responds to the server control event. the ispostback attribute executes the code conditionally.
4. Use the ASP. NET Server Control in an appropriate environment and only save the view status of the server control when necessary.Automatic view status management is a function of the server control. This function enables the Server Control to re-fill their attribute values during the round-trip process. However, because the view status of the server control is redirected to and from the server in the hidden form field, this function does have an impact on performance. You should know under which circumstances the view status will be helpful and under which circumstances it will affect the page performance. By default, view status is enabled for all server controls. To disable view status, set the enableviewstate attribute of the control to false. If you don't feel this way, you can view the source code on the page, and you can see a long string of viewstate. For more information about viewstate, see my other blog post.
5. Do not rely on exceptions in the code. The exception in the Code is the legendary try {...} catch {...} finally {...}.In the absence of exceptions, exceptions do not affect the performance of the application. However, if exceptions occur, the exceptions greatly reduce the performance. Therefore, as a professional and excellent programmer, we should not use them as a way to control normal program processes. If the code may cause exceptions, perform this operation. Do not capture exceptions before processing the status.
6. Use the CLR Garbage Collector and automatic memory management as appropriate.Be careful not to allocate too much memory for each request. In this way, the garbage collection period must be more frequent and more work will inevitably affect the application efficiency.
7. Use SQL Server Stored Procedures for data access.In many cases, it is better to write a stored procedure to write an SQL statement. Because the stored procedure is directly executed on the database server, the SQL statement we write in the application will be executed in the application and then executed on the database server, the database does not know this SQL statement. It will have a conversion process, which will take some time. Among all data access methods provided by. NET Framework, SQL Server-based data access is a recommended choice for generating high-performance, scalable Web applications. When using a hosted SQL Server Provider, you can use compiled stored procedures instead of special queries to obtain additional performance improvements. This is why companies require programmers to familiarize themselves with the stored procedure during recruitment!
8. If you can, use the sqldatareader class whenever possible to quickly read data . While at work, we still like to make sqldataadapter put the read data in the able, because we can completely read the data and put it in memory, like a table, then we can conveniently operate the data table. However, the efficiency is low. The sqldatareader class provides a method for reading data streams only retrieved from the sqlserver database. If you are allowed to use an ASP. NET application when creating it, The sqldatareader class provides higher performance than the dataset class. This is because sqldatareader uses the Local Network Data Transmission Format of SQL Server to directly read data from the database connection. In addition, the sqldatareader class implements the ienumerable interface, which allows you to bind data to server controls.
9. If possible, cache data and page output. there are two points to note when using the ASP. NET cache mechanism. First, do not cache too many items. Each item in the cache has an overhead, especially for memory usage. Do not cache items that are easy to recalculate and rarely used. Second, the period of validity allocated to cached items should not be too short. Items that expire soon will result in unnecessary turnover in the cache, and often lead to more code cleanup and garbage collection work.
10. Only enable authentication for the desired application. by default, the authentication mode is windows, or NTLM is integrated. In most cases, it is best to
machine. disable authentication in the config file and. enable authentication in the config file.
Okay, so are my suggestions! Thank you ~~~