ASP.NET Performance: Prefetch and Multi-Core Jitting

Xinyang Qiu

Editor note: This blog is originally published by Jose Reyes – ASP.NET on 02-29-2012 in Web Performance Blog, which will be obsolete soon.  Future ASP.NET related performance blogs will be posted here.

Introduction.

A couple of new features are introduced in ASP.NET 4.5 to improve startup time of web apps. Both features use a flag on the web.config to enable them. The features don’t do any magic by themself. They just enable features available on the operating system underneath or in the CLR APIs.

Prefetch feature

The prefetch feature only works on Windows 8 Server or newer OS. It requires the Os to be configured and the enablePrefetchOptimization flag on the <system.web/compilation> section of web.config to be set. The flag only has effect at the app level. No subdirectory config or location tag makes sense here. The setting is set to false by default, so users must explicitly set it to true in order for it to work.

To enable the feature, run the Enable-MMAgent power shell command:

    powershell Enable-MMAgent -OperationAPI

The SuperFetch service might need to be started. Verify is running:

C:>sc query sysmain

 

SERVICE_NAME: sysmain

        TYPE               : 20  WIN32_SHARE_PROCESS

        STATE              : 4  RUNNING

                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)

        WIN32_EXIT_CODE    : 0  (0x0)

        SERVICE_EXIT_CODE  : 0  (0x0)

        CHECKPOINT         : 0x0

        WAIT_HINT          : 0x0

Prefetch Implementation.

The features simple uses the operation recorder API. See OperationStart and OperationEnd APIs on msdn. This APIs require an integer used as an Id of the operation. We use a hash code of the app domain app id, which is a string.

string domainId = HttpRuntime.AppDomainAppId;

int operationId = domainId.GetHashCode();

 

The OperationStart call is made the first time the app domain is created. The OperationEnd API is called at the end of the request in which we called OperationStart. A .pf file should be created on the prefetch directory:

C:>dir %windir%Prefetch

Volume in drive C has no label.

Volume Serial Number is CC5B-113C

 

Directory of C:WindowsPrefetch

 

02/16/2012  04:17 PM    <DIR>          .

02/16/2012  04:17 PM    <DIR>          ..

02/16/2012  04:17 PM           164,832 Op-W3WP.EXE-90E54C33-765F360E.pf

               1 File(s)        164,832 bytes

               2 Dir(s)  30,203,154,432 bytes free

Multi-Core Jitting feature.

The multi-core jitting feature is enabled by default, and work on all OS where ASP.NET 4.5 is available. You can disable it by setting the profileGuidedOptimizations enumerated value on the <system.web/compilation> section on the web.config, to None.

Multi-Core Jitting Implementation.

The feature uses the new class ProfileOptimization class of the System.Runtime namespace. The class is called the first time the app domain is created. First, we set the profile root to the codegen directory, which by default is something like:

“%windir%Microsoft.NETFramework64v4.0.30319Temporary ASP.NET Filesmyappweirdhash1weirdhash2″

Remember that the temporary files folder value can be changed on tempDirectory attribute of the <system.web/compilation> section of the web.config.

After setting the profile root, we call StartProfile() with the filename “profileoptimization.prof”. The CLR code underneath handles all the magic. If you examine the contents of the temporary ASP.NET file folder, you will see the file there:

C:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Filesdotnetnuke59a60e53a2ac2624>dir *.prof

Volume in drive C has no label.

Volume Serial Number is CC5B-113C

 

Directory of C:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Filesdotnetnuke59a60e53a2ac2624

 

02/16/2012  04:38 PM             9,828 profileoptimization.prof

               1 File(s)          9,828 bytes

               0 Dir(s)  30,203,035,648 bytes free    

Conclusion.

The ASP.NET Prefetch feature uses the operation recording APIs to improve startup time of web applications. The feature is enabled when a Windows Server 8 machine is configured for the operation API and enabledPrefetchOptimization flag is set on the web.config.

The multi-core jitting feature is available in more operating systems and is on by default. It uses a new CLR feature for profile base optimization.

Thanks for reading.

Originally posted at http://blogs.msdn.com/b/josere/

0 comments

Discussion is closed.

Feedback usabilla icon