All .NET assemblies on windows server are very slow
I have very simple trivial C # code compiled in .NET exe
assmebly:
using System;
class Program
{
public static void Main()
{
Console.WriteLine("test");
}
}
The compiled build runs on my desktop Windows 8.1
for about 0.02
seconds each time, but in production Windows Server 2012 R2
it runs in 1.05
seconds.
Here's the PowerShell I'm testing with :
$sw = [Diagnostics.Stopwatch]::StartNew()
for ($i=1; $i -le 10; $i++)
{
.\cs.exe
}
$sw.Stop()
$sw.Elapsed
Output on my local computer :
TotalMinutes : 0.00391715666666667
TotalSeconds : 0.2350294
TotalMilliseconds : 235.0294
.NET versions on my local machine:
PSChildName Version
----------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.5.51641
Full 4.5.51641
Client 4.0.0.0
Server output :
TotalMinutes : 0.172228565
TotalSeconds : 10.3337139
TotalMilliseconds : 10333.7139
.NET version on server:
PSChildName Version
----------- -------
Client 4.5.51650
Full 4.5.51650
Client 4.0.0.0
Environment variables on the server:
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\*********\AppData\Roaming
CLIENTNAME *********
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME *********
ComSpec C:\Windows\system32\cmd.exe
COR_ENABLE_PROFILING 7
COR_PROFILER {8019fee9-9590-4bd4-b2c9-815628f80f0f}
CORECLR_ENABLE_PROFILING 0
FP_NO_HOST_CHECK NO
HOMEDRIVE C:
HOMEPATH \Users\*********
JAVA_HOME C:\Progra~1\Java\jdk1.8.0_45
LOCALAPPDATA C:\Users\*********\AppData\Local
LOGONSERVER \\*********
NUMBER_OF_PROCESSORS 12
OS Windows_NT
Path C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System3...
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL
PROCESSOR_ARCHITECTURE AMD64
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 3f02
ProgramData C:\ProgramData
ProgramFiles C:\Program Files
ProgramFiles(x86) C:\Program Files (x86)
ProgramW6432 C:\Program Files
PSModulePath C:\Users\*********\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPow...
PUBLIC C:\Users\Public
SESSIONNAME RDP-Tcp#126
SystemDrive C:
SystemRoot C:\Windows
TEMP C:\Users\ACADWE~1\AppData\Local\Temp\2
TMP C:\Users\ACADWE~1\AppData\Local\Temp\2
USERDOMAIN *********
USERDOMAIN_ROAMINGPROFILE *********
USERNAME *********
USERPROFILE C:\Users\*********
windir C:\Windows
What can cause this slowness in 1 second?
Is the JIT compiler a problem?
Is there any CLR related service that needs to run on the server?
Are there any app validation checks that can be disabled?
This problem only occurs with .NET exe files. Simple executables compiled from C ++ for 0.01
seconds
Edit:
I tried to run ngen.exe ExecuteQueuedItems
as suggested in the comments, but nothing changed. Here is the output from the command:
PS C:\Windows\system32> C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe ExecuteQueuedItems
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.33440
Copyright (c) Microsoft Corporation. All rights reserved.
All compilation targets are up to date.
source to share
I found the problem.
The dotMemory server seemed to be installed .
The following environment variables were also set:
COR_ENABLE_PROFILING 7
COR_PROFILER {8019fee9-9590-4bd4-b2c9-815628f80f0f}
CORECLR_ENABLE_PROFILING 0
After removing dotMemory and removing those environment variables, everything works as expected ( 0.02
seconds to start C # app)
source to share