Ramasamy NP
Ramasamy NP

Reputation: 131

How to improve performance of ASP.NET MVC WEB API?

I am developing web api in Visual studio 2012 and returning JSON result for each api call.

How to improve performance of WEB API?

Upvotes: 2

Views: 5127

Answers (6)

NicoJuicy
NicoJuicy

Reputation: 3528

I just did a test, using the nuget package WebApiContrib.Formatting.ProtoBuf and the filesize decreased from 9,5 mb ( json) to 3,35 mb ( protobuf) for 25000 objects.

Also, you can use SQL instead of EntityFramework for large queryresults.

If you use AutoMapper to convert from your POCO to DTO, you could manually set the properties ( much faster serialization)

And minimize your Filters and HttpModules, the lighter it is, the faster it goes.. ( eg. Authentication filter, ... )

Upvotes: 0

Hugues
Hugues

Reputation: 26

Performance depends on what you are doing with the Web API framework. Maybe you should look at a MVC profiling tool : http://msdn.microsoft.com/fr-fr/library/2s0xxa1d.aspx

Upvotes: 0

Ilan Y
Ilan Y

Reputation: 107

Use protobuf for serialization of data over the wire.

Upvotes: 0

xoyoja
xoyoja

Reputation: 436

First of all, your architecture matters. 80% root causes of the performance issues are architectural. We are not aware of your architecture.

From my point of view, reverse proxy can be used to facilitate load balancing over the application server clusture. On the application server layer, do you have clustering strategy? Do you have caching strategy to avoid visiting database?

.....

In general, you need to balance architecture scalability, reliability, extensibility, security, availability, and performance.

Upvotes: 0

SoftSan
SoftSan

Reputation: 2472

You should keep following things in your mind while designing a web API:

HTTP Compression — HTTP compression can be used both for response bodies (Accept-Encoding: gzip) and for request bodies (Content-Encoding: gzip) to improve the network performance of an HTTP API

HTTP Caching — Provide a Cache-Control header on your API responses. If they’re not cacheable, “Cache-Control: no-cache” will make sure proxies and browsers understand that. If they are cacheable, there are a variety of factors to consider, such as whether the cache can be shared by a proxy, or how long a resource is “fresh”.

Cache Validation — If you have cacheable API hits, you should provide Last-Modified or ETag headers on your responses, and then support If-Modified-Since or If-None-Match request headers for conditional requests. This will allow clients to check if their cached copy is still valid, and prevent a complete resource download when not required. If implemented properly, you can make your conditional requests more efficient than usual requests, and also save some server-side load.

Conditional Modifications — ETag headers can also be used to enable conditional modifications of your resources. By supplying an ETag header on your GETs, later POST, PATCH or DELETE requests can supply an If-Match header to check whether they’re updating or deleting the resource in the same state they last saw it in.

Chunked Transfer Encoding — If you have large content responses, Transfer-Encoding: Chunked is a great way to stream responses to your client. It will reduce the memory usage requirements (especially for implementing HTTP Compression) of your server and intermediate servers, as well as provide for a faster time-to-first-byte response.

Statelessness — Always keep application servers state-free so that they can be easily and painlessly scaled.

Bulk Operations — Most clients will perform better if they can issue fewer requests to fetch or modify more data. It’s a good idea to build bulk operations into your API to support this kind of use case.

Upvotes: 5

Whitesmell
Whitesmell

Reputation: 204

This is topic too big. Any specific detail?

Most of the ASP.NET Performance tips may apply to web api: http://msdn.microsoft.com/en-us/library/cc668225.aspx

Upvotes: 0

Related Questions