We have found that several CPU intensive queries mean that our API server no longer responses to simple requests. The API server is an .net core application with kestrel, which is executed in a Kubernetes cluster. However, if the application is running on a Windows or Linux host, the task prioritization seems to work perfectly. The service is responding even if there are dozens of CPU intensive requests. So there seems to be a significant difference between the Docker environment and the host environment.
I use this API method for test purposes:
public void SimulateHighCpuLoad()
{
var previousPriority = Thread.CurrentThread.Priority;
try
{
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
var until = DateTime.Now.AddSeconds(30);
var num = 0L;
var random = new Random();
// do senseless work for 30 seconds
while (DateTime.Now < until)
{
num = (random.Next() + Environment.TickCount + num) % (random.Next(10000) + 1);
num *= num++;
}
}
finally
{
Thread.CurrentThread.Priority = previousPriority;
}
}
My goal is to prioritize CPU intensive methods lower so that the application can always respond to other requests (such as health requests for the LivenessProbe). The Thread.Priority seems to be completely ignored within docker enviroment