Skip to content

Instantly share code, notes, and snippets.

@daxfohl
Created June 28, 2019 19:47
Show Gist options
  • Save daxfohl/33007d5d0c31b75d3e9d4c1d2971b6bd to your computer and use it in GitHub Desktop.
Save daxfohl/33007d5d0c31b75d3e9d4c1d2971b6bd to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"GCSettings.IsServerGC = {System.Runtime.GCSettings.IsServerGC}");
Console.WriteLine($"GCSettings.LatencyMode = {System.Runtime.GCSettings.LatencyMode}");
Console.WriteLine($"GCSettings.LargeObjectHeapCompactionMode = {System.Runtime.GCSettings.LargeObjectHeapCompactionMode}");
new Thread(() =>
{
var timer = new Stopwatch();
while (true)
{
timer.Restart();
Thread.Sleep(1);
timer.Stop();
if (timer.ElapsedMilliseconds > 2) Console.WriteLine($"GC Pause {timer.ElapsedMilliseconds}");
}
}).Start();
var random = new Random();
new Thread(() =>
{
var counter = 0;
var array = new byte[20000][];
while (true)
{
var bytes = new byte[random.Next(80 * 1024)];
random.NextBytes(bytes);
var index = counter % array.Length;// random.Next(array.Length);
if (index == 0) Console.WriteLine("cycle");
array[index] = bytes;
var lohBytes = new byte[90 * 1024];
if (++counter % 5 == 0) Thread.Sleep(1); // So we don't thrash the CPU!!!!
}
}).Start();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment