. NET Performance Optimization Tips

Source: Internet
Author: User

. 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.

HttpClientThe 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

ModelConsider 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
    1. If you need to insert a lot of data at the same time, use BulkCopy actions to improve performance

    2. Update/Query condition optimization, use more accurate conditions, use primary key to query and update whenever possible

    3. 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

    4. 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

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.