. net core memory recycling mode and performance test comparative analysis


. net core two GC modes:

Server GC / Workstation GC

Server GC :

It is mainly used in multiprocessor systems, and as a ASP.NET Default configuration for the core host. It creates a GC heap for each processor and performs the recycle operation in parallel. The GC of this mode can maximize throughput and better shrinkage. The characteristic of this mode is that the initial allocated memory is large, and the memory is not recycled as much as possible. It will take a lot of time to recycle and defragment the memory. In a simple word, this is greedy mode, which achieves better performance by getting as much memory as possible and reclaiming less. The result is high memory usage and good performance.

Workstation GC :

It is mainly used in single processor system. Workstation GC improves performance by reducing the number of program pauses during garbage collection. Low load applications that do not often perform tasks in the background (such as services) can use workstation garbage collection with concurrent garbage collection disabled. It is characterized by frequent recycling to prevent a long-term recycling. The result is low memory usage and poor performance.

Simple test

The following test results are all on the same computer, and the configuration is as follows:

•Windows 7 Ultimate

•Intel Core I3-3220 @ 3.30 GHZ

8g memory, 3gb of available space

•SQL Server 2014

The tested program is zkeacms, home page, single-sided stress test, 5000 requests, 1000 concurrent. The test results are as follows:

Server GC :

The response results are as follows, about 167.81 req / s. This result is not the same every time, and there will be some deviation, for reference only:

When the memory usage increases to about 600 m, there will be ups and downs, as shown in the figure below

After repeated tests, the maximum memory is more than 800 m, which is related to the available memoryMore memory availableAnd it’s going to go up to 1g or higher, and thenFall down againTo:

Workstation GC :

The response results are as shown in the figure below, about 151.33 req / s, which seems to be a little worse than that of server GC, and the results of multiple tests are generally worse.

The memory usage has been floating around 200m. Repeated stress tests will not cause big ups and downs. This is related to its active recycling

Switch of memory recycling mode

Now that you have a certain understanding of the impact of the different memory recycling patterns of. Net core, you can make a choice based on your personal situation. The default greedy mode of. Net core can get better performance, which is no problem. After all, it is a waste of memory to not put it there. Of course, if you have a lot of programs running on your server, and have a high memory limit requirements, do not affect other programs, then you have to do some configuration.

development environment

In the development environment, you can edit your project file, add the following configuration and rebuild it:


production environment

You can directly find *. In your program without modifying and relocating runtimeconfig.json For example: ZKEACMS.WebHost.runtimeconfig . JSON, modify“ System.GC.Server “: false, restart the program

"configProperties": {
 "System.GC.Server": false

reference material: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals

The above comparison and analysis of. Net core memory recycling mode and performance test is the whole content shared by Xiaobian. I hope to give you a reference, and also hope that you can support developpaer more.