I try to precompile my Azure WebApplication, so the first hit doesn't take multiple seconds for every first hit of a page.
I have the following code in my WebRole.Run()
:
using ( var server_manager = new ServerManager() )
{
var main_site = server_manager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];
var main_application = main_site.Applications["/"];
var main_application_pool = server_manager.ApplicationPools[main_application.ApplicationPoolName];
string physical_path = main_application.VirtualDirectories["/"].PhysicalPath;
main_application["preloadEnabled"] = true;
main_application_pool["autoStart"] = true;
main_application_pool["startMode"] = "AlwaysRunning";
server_manager.CommitChanges();
Log.Info( "Building Razor Pages", "WebRole" );
var build_manager = new ClientBuildManager( "/", physical_path );
build_manager.PrecompileApplication();
Log.Info( "Building Razor Pages: Done", "WebRole" );
}
It doesn't seem to throw any Exceptions and when I look into the log it takes about 55 seconds to do build_manager.PrecompileApplication()
.
Seems about correct to me.
Except that when I try to load the pages the first time it still takes a hit. If I look into the MiniProfiler I see specificly that the Find part takes long. I still suspect it is the compilation, because 1.5 seconds just to find a file seems a bit long to me.
Is there anything wrong with my approach above? Is there a way to check if the page is really compiled? And in the case it is compiled, what else could it be? And why o why is stuff so complicated..