ASP. NET application performance optimization

Source: Internet
Author: User
Tags server memory
Guidance:
1 Preface
The main goal of performance optimization is to increase the "number of concurrent users", "throughput", and "reliability" indicators.
In essence, performance optimization should be performed in many aspects, and "Point-to-face integration, from table to inside" should be implemented ". For example, from the perspective of cost, we should try to make the changes small and easy to implement; from the perspective of users, we should make quick responses or prompt; from the perspective of software structure, it also takes into account the rationality and scalability of the system structure. It is not difficult to find that it is difficult to implement all aspects when trying some improvement methods.
Here is a simple example:
In a business logic class, we encapsulate some processing methods. One of the methods is to find whether a node ID already exists in the XML file. Then we will naturally think of writing two methods:
Xmldocument loadxml (string strfileid) // load XML
Bool checkidexisit (string strfileid, string Strid) // determine whether a node exists
In addition, the XML loading method can be reused elsewhere. On the surface, the structure and functions of the Code are correct. However, when you call loadxml multiple times in your logic, you will find that the program is slow. The reason is that loading XML files is a time-consuming action, and the solution is simple. We can provide several more methods:
Bool checkidexisitbyxml (string strxml, string Strid) // you can check whether a node exists.
Or bool checkidexisitbyxml (xmldocument objxml, string Strid) // you can check whether a node exists.
In this way, we can use "one-time loading" to implement multiple borrow operations, significantly improving the efficiency. Therefore, factors that can reuse "Precious" data sources should be taken into account in software structure design. (Here the "Precious" data source refers to various objects or record sets that are obtained after complex processing or long computing ).
Performance optimization work should be long-term, because our work is always based on OS, web server, DB server, complier & program language and so on. If you are familiar. net, Java, IIS, and J2EE, you will find that some functions or APIs are provided on this platform, but the other is not; so more often we need a transitional solution, when the new version comes out, we may discard the transition scheme for direct configuration or easier implementation of some features. [...]
2 Requirements
The first step in performance optimization is to check whether the requirements are reasonable. This is a review of the project itself. In a sense, it is an escape principle. However, from the perspective of software engineering, this is necessary, because the customer's needs are endless, and any software has a life cycle, and the OS is not to mention the application software. We always want the user to display the better and farther separation from the business logic, but ignore a basic problem: how to define the I/O relationship between the two, it is very important to allow them to cooperate effectively and ultimately satisfy users.
Therefore, in performance optimization, the need for re-check is to define user interaction to make it more scientific. Looking at the industry's development trends, there are already dedicated people studying user interaction, just like the so-called "Industrial Design" in the traditional industry, which is becoming more and more important!
When checking back, the requirement is often changed. At this time, we should combine the opinions of "requirement definition personnel" and "developers", because different parties have different perspectives and must learn from each other.
3 Interactive Response
As mentioned above, performance optimization can be performed in the "from the table to the inside" order. There are two main considerations:
First, this is what the user sees directly, and the effect is quick;
Second, modification is less difficult than kernel modification.
Applications based on the B/S structure have problems with front-end (User) Interaction with backend (server, therefore, the interaction response process includes two processes: "backend computing" and "loading to the client. Obviously, if we try to reduce the amount of data that needs to be downloaded to the client, the response time will be reduced.
According to the test, we found that it takes about 35 seconds to bind 40 thousand records to the grid. In fact, we will not display so many records on the page at once, and it is impossible for users to browse so many records at once. Usually we use paging, and the so-called paging is only a re-binding of data. Therefore, if we only bind the requested page each time, the data volume to the client will drop sharply. This is our idea of "computing all data and loading local data" (for example ).
  
  
  
From the user's perspective, we can look at the other two problems. People who used ASP applications will find ASP. NET applications are frequently refreshed. A small action must be submitted to the server for processing. From the perspective of software design, we feel very reasonable because there is no coupling and the logic can be reused. However, we should still adopt the method of turning between the fish and the bear's paw. Back to our system, we found that most pages reread and rebind from the database for each frequently used "add, delete, and modify" operation. The user does not recognize the frequent refresh, and the interaction time is also affected if the data volume is large.
In fact, if the data is displayed in the grid, you do not need to load the data during deletion or modification. You can simply use the control method, although it will also be submitted, it is significantly different from rebinding, and the speed is much faster! For a Treeview, "add-delete-modify" does not need to be re-loaded because it does not need to be paged.
Another problem is that, although users can understand the complex and possibly time-consuming computing process, they should still give a prompt or progress bar. This is not in the scope of performance optimization, but is an important UI specification. We recommend that you include it in the test requirements. There are two ways to display the progress bar:
1. The front-end displays the waiting or completion progress, the backend finishes processing, the front-end progress bar is closed, and the processing result is displayed;
2. After submitting the task to the background, go to a waiting page. After the background is complete, go to the confirmation page. This method is generally based on the XMLHttpRequest [13] technology and creates a separate computing thread in the background. The advantage is that the client is not reflected for a long time in the first display mode because the background is too busy, the progress bar does not move.
4 Deployment
Deployment is actually a big concept, covering both software and hardware. The system deployment structure, software configuration, and hardware configuration are all included in the scope of deployment. I will not go into details about how to deploy a software system here. I will only list some specific practices.
4.1 ASP. NET
When a large amount of data is transmitted, an exception "out of memory" is often encountered. In this case, the memorylimit attribute value in the processmodel subitem in the machine. config file can be adjusted so that. Net can use more memory.
4.2 others
4.2.1 optimize Server & IIS configuration
4.2.1.1 expand IIS Cache
The server retains a portion of the memory space used as the IIS cache to store objects for future requests. In this way, IIS can retrieve objects from the cache instead of from the hard disk. To adjust the IIS cache capacity, You need to modify the registry. The table items are as follows:
HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/inetinfo/parameters/memorycachesize
= 0x 1e84800 (type: REG_DWORD, using hexadecimal notation .)
The value can also be set to decimal, ranging from 0 to 4 GB. The default value is 3072000 (3 MB ). Generally, this value should be at least 10% of the server memory.
IIS improves system performance by using the cache system handle, directory list, and other common data values. This parameter specifies the memory size allocated to the cache. If the value is 0, it means "no cache is performed ". In this case, the system performance may be reduced. If your server is busy with network communication and has enough memory, you can increase the value. Note that after you modify the registry, you must restart the Registry to make the new value take effect.
4.2.1.2 adjust the CPU usage time of IIS
The CPU processor capability of the server is always limited. Which application occupies the longest processor for the maximum performance improvement.
(1) On the NT control panel, double-click the System icon.
(2) Click the performance tab.
(3) drag the cursor to the none position under the application's procedural ability, so that all running services, including IIS, can use the processor to reach the maximum time.
(4) select to maximize the total processing capability of network applications. Click OK ."
4.2.1.3 protocol and Related Optimization
(1) to improve performance and save resources, only the required protocols should be run.
(2) the IIS server should be set as an independent server. Do not let the server bear the extra load required by the domain controller.
(3) You can distribute the Page Swap files of the NT Server to multiple physical disks. Note that multiple "physical disks" are not valid when distributed across multiple partitions. In addition, do not place the Page Swap file in the same partition as the Windows NT boot area.
(4) using a disk image or a disk zone set can improve the disk read performance.
(5) log records should adopt file records instead of logging to the ODBC data source. In addition, you can increase the memory buffer capacity used to record logs during the recording period to reduce disk activity. The default size of the buffer is 64 KB.
(6) It is best to store all the data in a separate partition. Then, run the disk fragment program regularly to ensure that no fragments exist in the partition where the Web server data is stored. Using NTFS helps reduce fragments.
(7) Although SSL can provide quite reliable encrypted transmission. However, the additional overhead will cause the IIS server to speed down, especially when processing large files. Therefore, you should only perform SSL encryption on directories that do need to be protected.
4.2.1.4 adjust the expiration time
HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/inetinfo/parameters/objectcachettl = 0x8ca0.
4.2.1.5 adjust the maximum number of threads
HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/w3svc/asp/parameters, increase processorthreadmax, reduce this value, and see performance changes; or increase the value .)
4.2.1.6 other optimizable items in the Registry
Take "HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/inetinfo/parameters/" as the parent node;
Cachesecuritydescriptor indicates whether security descriptors are cached for file objects. A value of 1 enables this feature. A value of 0 disables this feature. when enabled (the default setting), security descriptors for files are saved when caching a file object. as long as the file is cached, IIS will not need to re-access the file to determine access rights for new users. this value is most useful for sites that authenticate users and not useful for sites that allow anonymous access.
Checkcertrevocation indicates whether IIS checks to see if a client certificate is revoked. if you issue your own certificates and make local certificate checks, you might want to enable this feature. otherwise, the feature shocould be disabled, which is the default. A value of 1 enables this feature.
Disablememorycache indicates whether IIS Memory caching is enabled or disabled. By default, memory caching is enabled (meaning this value is set to 0). Disable memory caching only for testing or development purposes.
Listenbacklog specifies the maximum number of active connections that IIS maintains in the connection queue. The default value is 15 and the range of acceptable values is from 1 to 250.
Maxcachedfilesize determines the maximum size of a file that can be placed in the File Cache. IIS will not cache files that are larger than this value. The default value is 262,144 bytes (256 KB ).
Maxconcurrency specifies how many threads per processor shocould be allowed to run simultaneously if there is a pending input/output (I/O) operation. the default value (0) allows IIS to control the number of threads per processor. you can also set a specific value.
Maxpoolthreads sets the number of pool threads to create per processor. each pool thread watches for a network request for a CGI application and processes it. this value does not control threads that are used by ISAPI applications. by default, the value is set to 4. on a single processor system, this means that only four CGI applications cocould run simultaneously.
Memcachesize sets the maximum amount of memory that IIS will use for its File Cache. if IIS does not need this much memory, it will be left for other applications to use. by default, IIS uses 50 percent of the available memory. the valid range is from 0 megabytes to the total amount of physical memory available in megabytes.
Objectcachettl sets the length of time (in milliseconds) that objects are held in memory. if the object hasn' t been used in this interval, It is removed from memory. the default value is 30 seconds (300,000 milliseconds ).
Poolthreadlimit sets the maximum number of pool threads that can be created on the server. This limit is for all IIS threads. The default value is twice the size of physical memory in megabytes.
4.2.1.7 disable unnecessary services:
Disable Windows 2000 services that are not required by dedicated web servers. Click Start, point to programs and management tools, and click computer management. Under computer management (local), expand services and applications, and then click Services. The Status column of the currently running service shows that it has been started. The following services are not required on dedicated web servers:
Alarm
Clipboard
Computer Browser
DHCP Client
DHCP server
Fax Service
File Replication
Infrared Monitor
Internet Connection Sharing
Messenger
NetMeeting Remote Desktop Sharing
Network DDE
Network DDE DSDM
Nwlink Netbios
Nwlink IPX/SPX
Background print program
TCP/IP NetBIOS Support Service
Phone number
Telnet
Uninterruptible Power Supply
========================================================== ==========
Write down the services that are dependent on the services to be stopped. The method is:
Double-click the required service. For example, double-click the messenger.
Click the dependency tab.
In the "service name depends on these services" list (where the service name is the name of the selected service), write down the services that the service depends on.
In the "these services depend on service names" list, write down the services that cannot be started without the service.
Click OK.
Disable the required services. The method is:
Right-click the service you want to disable, and click Properties on the shortcut menu that appears.
In the launch type list, click Disable.
To stop the service immediately, click STOP. If the "Stop Other Services" dialog box is displayed, other services dependent on this service will also be stopped. Write down the affected services and click yes.
Click OK. The service is disabled in the Startup type column.
Repeat Step 1 to disable other unnecessary services.
Note: after each service is disabled, check whether the Web server computer is running properly. This minimizes the impact of disabling services that may be required.
Note: If the IIS server is a Windows 2000 Domain Member, the TCP/IP Support Service is required to correctly apply the Group Policy to the computer.
4.2.1.8 maximize network application data throughput
Run the paging code of the IIS 5.0 process in the working memory. The method is:
Right-click the network neighbor on the desktop, and click Properties in the shortcut menu that appears.
Right-click the desired local connection icon and click Properties in the shortcut menu that appears.
In the "use the following selected components for this connection" list, click "file and printer sharing for Microsoft Network" (but do not clear its check box), and then click Properties.
Click maximize network application data throughput, and then click OK twice.
4.2.1.9 optimize the performance of background services
IIS 5.0 process (inetinfo.exe) runs as a background service. To improve the performance of background services, follow these steps:
Click Start, point to settings, and then click Control Panel.
In control panel, double-click the system.
Click the Advanced tab, and then click performance options.
Under "application response", click "background service", and then click OK twice.
Exit Control Panel ".
4.2.1.10 minimize IIS 5.0 Logging
Do not record unnecessary web sites, virtual directories, files, or folders. The method is:
Click Start, point to programs and management tools, and then click Internet Service Manager.
Expand "* server name", where the server name is the name of the Web server.
Find the required item and right-click it. On the shortcut menu that appears, click Properties. For example, right-click the default web site and click Properties on the shortcut menu that appears.
Perform one of the following operations:
If you select a Web site, click the Home Directory tab.
-Or-
If you select a virtual directory, click the virtual directory tab.
-Or-
If you select the actual directory, click the Directory tab.
Click the Log Access check box, clear it, and click OK.
To Disable Logging for the entire web site, click the web site tab, click the Enable Logging check box, clear it, and click OK.
Exit the Internet Information Service Management Unit.
4.2.1.11 enable bandwidth limit
Limit the available network bandwidth of each web site. The method is:
Start Internet Service Manager ".
Expand "* server name", where the server name is the name of the Web server.
Right-click the desired web site (for example, the default web site), and click Properties on the shortcut menu that appears.
Click the performance tab, and then click the Enable bandwidth limit check box to select it.
In the "maximum network usage" box, type the desired value and click OK.
Exit the Internet Information Service Management Unit.
4.2.1.12 limit processor usage
Restrict the CPU usage of websites. The method is:
Start Internet Service Manager ".
Expand "* server name", where the server name is the name of the Web server.
Right-click the desired web site (for example, the default web site), and click Properties on the shortcut menu that appears.
Click the performance tab, and then click the enable process restriction check box to select it.
In the "Maximum CPU usage" box, type the value you want.
Click the mandatory limits check box, select it, and click OK.
Note: If the mandatory restriction option is not enabled, the "Maximum CPU usage" restriction is not enforced. When the web site exceeds its allowed CPU usage limit, the event is written into the "event log.
Exit the Internet Information Service Management Unit.
4.2.1.13 restrict web site connection
Limit the number of available connections for each web site. The method is:
Start Internet Service Manager ".
Expand "* server name", where the server name is the name of the Web server.
Right-click the desired web site (for example, the default web site), and click Properties on the shortcut menu that appears.
Under connection, click Limited.
In the connection box, type the number of connections to be allowed.
Note: Each Client Connected uses approximately four connections at the same time. For example, limit the number of connections to 200 to allow about 50 users to access the web site.
Click OK to exit the Internet Information Service Management Unit.
4. 2.1.14 use "Keep HTTP Connection"
By default, you can use "Keep HTTP Connection ". To verify whether "Keep HTTP Connection" is enabled, follow these steps:
Start Internet Service Manager ".
Expand "* server name", where the server name is the name of the Web server.
Right-click the desired web site (for example, the default web site), and click Properties on the shortcut menu that appears.
Under the connection, confirm that the "keep HTTP connection enabled" check box has been selected, and then click OK.
Exit the Internet Information Service Management Unit.
4.2.2 optimizing the configuration of dbserver
4.2.2.1 sqlserver
Memory is an important factor affecting the performance of Microsoft SQL Server.
When the SQL Server database is installed, 16 MB of available memory is configured by default for machines with 32 MB physical memory, and 4 MB of available memory is configured by default for machines with 16 MB physical memory. You should set the memory option (memory) after installing the Microsoft SQL Server database. In order to determine the most suitable memory requirements for the SQL server system, we can combine the memory requirements of Windows 2000 server and other memory requirements from the total physical memory.
The following describes how to set the memory option (memory) of SQL Server:
(1) start SQL Enterprise Manager from the Microsoft SQL server program;
(2) Select the "server" menu option from the Server Manager window;
(3) Select the ations option from the "server" menu;
(4) In the "server configuration" dialog box, select the "configuration" tab,
(5) Select the "Memory" project and enter a new value in the "current" column;
(6) stop and restart the sqlserver service to make the settings take effect.
  
Reasonably expand the virtual memory and increase the available memory of SQL Server
When the SQL server system really needs to expand the available memory, it should be expanded to provide virtual
Memory, and correspondingly increase the available memory of SQL Server. Specifically, the system administrator first expands the virtual memory of the server, and then increases the available memory of the SQL Server by referring to the table above. The key is to determine whether to expand according to the overall load of the system.
Use tempinram
SQL Server uses the temporary database of tempdb to sort queries or create temporary tables.
Space. Creating tempdb in Ram can greatly improve system operability, And because tempdb is rebuilt every time the server is restarted, it is safer even if an abnormal shutdown occurs, for example, power failure. To create tempdb in Ram, you can use sp_configure to set it. For more information about the usage, see.
Because the memory used by tempdbinram is separately allocated by the system from the memory body
The available memory pools set in the item are separated. The use of tempdbin Ram will reduce the available memory of the entire system, and should be configured according to the SQL Server and server running conditions, otherwise it may be counterproductive, affects system performance. In addition, appropriately increasing the tempdb database space can speed up database operation even if you do not use tempdbin Ram.
Note: Do not set the SQL server memory to less than 32 MB in the production environment, and try to expand the database server to provide virtual memory and increase the available memory of SQL Server, physical memory usage and disk space should be considered; if possible, some additional memory should be reserved for the system, in this way, opening a service on the server or adding a process without changing the SQL server memory configuration does not affect the running speed of the NT Server (becoming slow ), generally, the minimum value is 2 MB and the maximum value is 20 mb.
4.2.3 hardware upgrade
4.2.3.1 CPU/memory
If the test determines a processor problem exists, your first option is to upgrade or switch the processor to a multi-processor computer. If you are sure you want to upgrade the processor, make sure that it has the largest L2 cache. IIS will benefit from this because many of its command paths contain multiple components, their Running Speed in high-speed cache will be greatly accelerated.
Computer Name/memory/available memory-this counter tracks the total amount of available memory in the system. The operating system tries to keep the value above 4 MB. To achieve the best performance, this value is preferably 5% of the total memory.
4.2.3.2 Hard Disk
Do not store log files and web pages on the same hard disk. This will prevent hard disk logging threads from interfering with the web page retrieval thread.
Optimize web page storage. All related web pages on the site should be stored in the same logical partition, which can improve the file system cache performance. At the same time, web page files should not contain any fragments, which can greatly speed up reading a single file.
If you use the SCSI hard disk of ultra2, the IIS performance can be significantly improved. Network interface card, memory upgrades are not required.
5 session management
The reason why HTTP is so successful is the simplicity of its design and implementation and the high efficiency of stateless connections. To balance stateless HTTP requests with stateful client operations, the concept of server-side session is introduced. The introduction of session greatly facilitates web programming, but the corresponding session management becomes very important. Currently, ASP. NET supports status management through "in-process", "dedicated out-Process status management service", and "SQL Server Status Service Management. The default "in-process" management method only implements memory-based status management in one process, so there are many problems:
1. all session data is stored in the Web service process, which may cause the number of sessions supported by the server to be limited by the memory resources of the server. In addition, memory usage is invalid because of a large number of inactive sessions.
2. server process crash may cause data loss of all sessions.
Back to our actual system, we currently use session variables for roughly four purposes:
  
Obviously, the first three methods are small data volumes. Here we mainly focus on the fourth method-session dataset variables.
Stores the entire dataset in the session, mainly for subsequent processing or secondary processing or re-binding when users flip pages, in general, we will ignore the impact of the dataset size on Web-server and interaction time during encoding. In fact, a large dataset (with more than 0.1 million records) occupies a considerable amount of space. If there are several concurrent data sets, the memory of the Web-server will be very tight. The following table lists the SQL Execution time statistics of actual tests.
One solution is to store the complex query conditions in the session. This method is simple and lightweight, but it will also cause "frequent queries lead to busy DB-server" (the query time of 0.5 million records is greater than 15 s ); the ideal solution is to query the database by page or by page. In this case, the session can only store the query conditions, because the interactive data volume is not large. This function can be easily implemented in Oracle and sqlserver2005, but it is troublesome to implement in sqlserver2000, and stored procedures are generally used.
Considering that the implementation of existing systems does not take into account the large data volume, and not every page or logic will have a large data volume, a single session management solution should not be used. In fact, we can construct Adaptive Data Access actuators and session managers to dynamically return and store execution results in different ways. Because the current session management mode of the system is "in-process" (inproc) mode and IIS does not provide a smooth configurable second-level (memory/hard disk) cache medium switch, therefore, you can create a virtual storage space to relieve the concurrency pressure. The following figure shows the overall structure of the solution:
  
  
  
First, let's take a look at the data access execution flowchart (Figure 5-3 ).
As shown in Figure 5-3, a time threshold value is set during query execution. If the execution is completed within the specified time, the result set is directly returned to the foreground if the data volume is not large; if the query times out, a small data set (such as top1000) is returned, and a thread is set up in the background to continue the query and save the final result set to the session, note that the current data set is usually large, but it may also be caused by the server busy, so we will use Session Manager to dynamically Save the data as appropriate.
  
Below is a simple sessionmanager class structure,
  
  
  
It must be noted that this is only a simple one. This structure will be greatly enriched in actual implementation. For example, you need to add the current session storage method and storage quantity. The purpose of implementing pagesessionmanager is to standardize the use of sessions, especially the use of session dataset variables. We will automatically select the storage mode based on the dataset size. The following is a flowchart for storing session dataset variables.
  
  
  
As you can see, we have introduced a new storage method in sessionmanager-virtual storage ). The objective is to relieve the web-Server Memory pressure and improve the concurrency. It has been detected that this method is still relatively fast. If the XML is saved to the database, a timeout exception occurs when the XML is obtained or the XML is read. In fact, we have constructed an out-of-process session manager by ourselves, so we naturally need to clear and manage sessions for failures. We can run a dedicated failure management process in the background, for specific implementation methods, see.
  
Another problem is how to establish the correspondence between a virtual storage file and an HTTP Process. This is not difficult. We only need to create a guid and store it in the actual session with the same name. The virtual session file name is identified by the guid.
As it corresponds to storage, sessionmanager automatically returns the corresponding results based on the current storage method when obtaining the session value through sessionmanager. The implementation process is not complex and will not be repeated here.
In general, this solution is characterized by increasing concurrency and ensuring rapid response, but it is inconvenient to handle some problems. For example, if you want to obtain all the datasets at a time (even if it is large) When querying the record set that requires secondary processing, you must set the corresponding property value to inform adaptiveexecutor to execute the data in the specified way. If there is a large data volume, the page control cannot instantly obtain the total number of pages at the end of the query.
6. Code
Code-level optimization refers to the improvement of specific code implementation, especially the algorithm of a business logic. The example in the preface is code optimization. Code optimization is deep-seated and requires familiarity with business logic and data streams, making it the most difficult. However, after removing the business logic, we can still reach a consensus on coding techniques or algorithm structures. This article mainly lists some methods and notes that should be mastered based on performance considerations in the actual coding process.
Do not use unnecessary sessions. Like ASP, do not use sessions when necessary.
Unnecessary Server Control
No unnecessary viewstate
Do not use exception to control program processes
Disable VB and JScript Dynamic Data Types
Complete data access using Stored Procedures
Do not use dataset for read-only data access
Disable ASP. NET debug mode
Use ASP. net output cache to buffer data
Try to use SQL to return the dataset to be bound to the DataGrid, and do not perform secondary processing on the dataset. In particular, do not delete the dataset in large quantities. Practice has proved that this is slow. It is better to copy part of the data.
Do not perform secondary data processing on dataset or splice data into an object set through dataset. Obviously, if there are 40000 records, it means to fight for objects greater than or equal to 40000 times.
Try to compress the number of database operations for data query to a minimum, and perform one or two database operations as far as possible. If you query each data item of the queried dataset, this means that if there are 40000 records, at least 400001 database operations must be performed, and the time taken to traverse dataset and generate objects is amazing.
Optimize database query operations. For example, do not use discrete values to retrieve them one by one during unconditional query;
Note that query operations on large data volumes are restricted. For example, if a page is not expected to contain a large amount of data if one condition is not added, at least one query condition is required;
Do not select all data by default during page loading. Although it is convenient for subsequent operations, the user will think that "no operation is so slow"
We recommend that you use highly efficient SQL instead of complex dataset secondary processing.
Open the database connection only when necessary
Once the database operation is complete, close the connection.
Remember to delete the temporary object when closing the connection.
Before closing the connection, make sure to close any user-defined transactions.
To use the connection pool, do not use the application role)
Displays non-interactive data and uses sqldatareader for optimal performance
Obtaining HTML code in SQL is better than displaying formatted data with DataGrid component.
In general, using indexes in a loop has better performance than using collections. Because CLR (Common Language Runtime) can sometimes be optimized based on data indexes, but the set is not
Share the data that is obtained after complex processing or long queries.
When you jump to the page, remember to terminate the processing of the current page.
If there are some irrelevant data processing logic in page loading or background computing, you can consider using multithreading. You can also consider loading pages gradually (response. Flush ())
Do not use + for string operations with a large number of connections. Use stringbuilder instead.
7 Reference
1. http://www.microsoft.com/technet/prodtechnol/windows2000serv/technologies/iis/maintain/optimize/perflink.mspx
2. http://www0.ccidnet.com/tech/web/2001/09/28/58_3369.html
3. http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpguide/html/cpconaspoptimization. asp
4. http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnpag/html/scalenetchapt06.asp
5. http://www.microsoft.com/china/technet/itsolutions/net/maintain/netopsgd.asp
6. http://www.programfan.com/showarticle.asp? Id = 2548
7. http://www.microsoft.com/china/msdn/library/webservices/asp.net/CachingNT2.mspx
8. http://www.programfan.com/showarticle.asp? Id = 2548
9. http://www.microsoft.com/china/msdn/library/webservices/asp.net/CachingNT2.mspx
Http://www.SQL-server-performance.com/asp_net_performance.asp
11. http://www.cnblogs.com/flier/archive/2004/08.html
Http://soft.yesky.com/SoftChannel/72342380468043776/20050223/1914105.shtml
13. http://jibbering.com/2002/4/httprequest.html

This article is transferred from
Http://idoall.org/blogs/ian/archive/2007/10/31/asp-net.aspx

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.