. NET Performance Optimization Tips intro
Before the promotion of the speed of sending text messages, under the guidance of the master, the speed of sending text messages has been greatly improved and learned some tips for improving. NET performance
HttpClient optimization
With regard HttpClient
to usage, probably a lot of people know how to use a single case to improve HttpClient
performance.
Due to the HttpClient
need for domain name resolution at the time of sending the request, it is generally slower to use the first time, we HttpClient
send a request to the destination address after the initialization is complete, which HEAD
will result in a cache of the domain name resolution. The time it takes to resolve the domain name in the actual request will be reduced, so that you can increase the speed of the first actual send request.
HttpClient
The time-out setting is as short as possible to avoid extra long waiting for increased response time
Synchronous Operation Optimization
The original synchronization operation, which can be processed asynchronously using asynchronous methods,
such as querying the database and other operations can be changed to asynchronous operations, reduce thread congestion, and further improve CPU utilization.
Scheduling multiple tasks, you can start tasks without having to worry about a task schedule, and you don't have to wait.
Data structure optimization
Model
Consider Model
whether there are more useless fields in the use of more places, and if any, consider using a new lightweight Model
, optimized Model
data structure to optimize memory storage.
Cache
The reused values are cached (depending on the data need to choose the cache type, the variable cache or the memory cache or distributed cache such as Redis), reduce the number of database queries
SQL optimization
If you need to insert a lot of data at the same time, use BulkCopy
actions to improve performance
Update/Query condition optimization, use more accurate conditions, use primary key to query and update whenever possible
Multiple operations for batch update data can be combined into one operation at a time, not one commit at a time, pay attention to anti-SQL injection
When complex SQL uses transactions, you can use transactions in SQL to use them in SQL or in your code. Transactions are only opened where transactions need to be opened, transactions are committed at the end of transactions, and database operations that do not need to be processed in a transaction are not doped in the transaction
End
Thank the master, followed by the master to perform a performance optimization, indeed learned a lot, oneself to some concepts also understand more deeply.
. NET Performance Optimization Tips