We recommend eight technologies to improve the performance of ASP. NET Web APIs, asp. netapi

Source: Internet
Author: User
Tags net serialization

We recommend eight technologies to improve the performance of ASP. NET Web APIs, asp. netapi

In this article, I will introduce eight techniques to improve the performance of ASP. NET Web APIs.

 1) Use the fastest JSON serialization Tool

JSON serialization has a critical impact on the performance of the entire ASP. NET Web API. In one of my projects, I switched from the JSON. NET serialization tool to ServiceStack. Text for a year and a half.

I have measured that the performance of Web APIs has increased by about 20%. I strongly recommend that you try this serialization tool. Here are some data on the performance of recent popular serialization tools.

Source: theburningmonk

Update: It seems that It seams that StackOverflow uses the fastest JSON serialization tool Jil they claim so far. For test data, see their GitHub page Jil serializer.

 2) manually serialize JSON from DataReader

I have used this method in my projects and have received performance benefits.

You can manually create a JSON string from DataReader and avoid unnecessary object creation. In this way, you do not need to take values from DataReader and write objects, value from these objects and use JSON Serializer to generate JSON.

Use StringBuilder to generate JSON and return StringContent at the end as the response content in the WebAPI.

var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(jsonResult, Encoding.UTF8, "application/json"); return response; 

You can view more methods on Rick Strahl's blog

 3) Try to use other protocol formats (protocol buffer, message pack)

If you can use other message formats in your project, such as Protocol Buffers or MessagePack, rather than JSON.

You can get a huge performance advantage, not only because Protocol Buffers is serialized very quickly, but also faster than formatting the returned results of JSON.

 4) Compression

Use GZIP or Deflate in your ASP. NET Web API.

Compression is a simple and effective method to reduce the size and speed of response packets.

This is a very necessary function, you can view

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.