Use Compression Techniques
Use compression techniques like gzip or Brotli to compress the data transferred from server to client. .NET Core has an inbuilt Response Compression Middleware for compression (default: gzip). GZIP is used for file compression and decompression for faster network transfer. Also, reducing the size of the response usually increases the responsiveness
Use Asynchronous methods
Asynchronous methods help to maximize the number of concurrent requests that can be handled by the API at a given point in time. By implementing asynchronous methods, you can leverage the multiple cores of the server and maximise application's throughput. Increases Scalability.
Call data access, I/O and long-running operations asynchronously
Use faster Data Access Strategies
In order for an app to be responsive, it is essential to retrieve data from database faster and efficiently. One suggestion would be to use ADO.NET over ORM since its lightweight. Also, can look for database query optimizations that can reduce the number of round trips made to to the database by combining multiple calls to a single call.
Use Caching
You can use Caching to cache API methods that return the same response frequently. Few Caching Techniques - Pivotal Cloud Cache (PCC), Redis, .NET Core Lazy Cache, Cloudfare(CDN)
Faster Media Type Formatters
JSON preferred over XML for message transmission since its lightweight
Implement Pagination
Limit the number of records returned in response by implementing Pagination techniques (skip/limit, next/prev APIs)
Understanding Hot Code Paths
A hot code path is a path of code that is called frequently and where most of the execution time occurs. Hot paths limit the application's ability to scale out and limit API performance if it's optimized correctly.
Make Hot Code Paths asynchronous. Profilers like PerfView, Resharper's dotMemory and dotTrace, ANTS Performance Profiler can be used to find hot code paths and also threads that are frequently added to the thread pool
Reduce allocating large objects in HEAP
Garbage collection is really expensive on large objects(>85KB). Unlike gen0 and gen1, gen2 collection needs the temporary suspension of app execution.
Avoid/minimize assigning large objects in Hot Code Paths
Keep Common Code Paths fast
Middleware components run very early in the request pipeline and run for every request. So middlewares like custom logging, authorization handlers or initialization of transient services should be optimized.
Long-running tasks should be performed separately
We should not be waiting for long-running tasks to finish to send the HTTP response back to the client. Instead, consider using background services for handling long-running requests.
Comments
Post a Comment