dotnet core notes


Preventing Memory Leak

1. read setting file always set reloadOnChange is false on release


1
2
3
var builder = new ConfigurationBuilder()
 .SetBasePath(Directory.GetCurrentDirectory())
  .AddJsonFile("appsettings.json", optional: true, reloadOnChange:false);

2. switch from server GC to workstation GC

Reference: https://blog.markvincze.com/troubleshooting-high-memory-usage-with-asp-net-core-on-kubernetes/

edit .csproj

1
2
3
<PropertyGroup> 
    <ServerGarbageCollection>false</ServerGarbageCollection>
</PropertyGroup>

Asyac

1. logger   

remember using async method to write log. Otherwise, your cpu will be high and the service will be slow.

below using nlog as example:

1
2
3
4
5
6
<targets async="true">
   <default-wrapper xsi:type="AsyncWrapper">
    <wrapper xsi:type="RetryingWrapper"/>
   </default-wrapper>
  ..........
</targets>

Cache

remember high traffic service must to set cache on Application, Database and Client
if you use cloud platform (AWS, Azure and GCP) , you can use CDN to reduce traffic for service


  • Application
    • use redis/cache server to cache not Infrequently changing data
  • Database
  • Client 
    • use http cache

Request Timeout

remember high traffic service must to set request timeout on Application and  Database

* AP
* DB

留言

熱門文章