经过很多谷歌搜索,我遇到了四种不同的策略(如下所示):
(a)在RoleEntryPoint.OnStart()中禁用IIS空闲超时
public overrIDe bool OnStart(){ using (var server = new ServerManager()) { server.ApplicationPoolDefaults.ProcessModel.IDleTimeout = TimeSpan.Zero; server.CommitChanges(); } return base.OnStart();}
这也要求角色在较高的水平上运行。
(b)在RoleEntryPoint.Run()中定期执行请求
public overrIDe voID Run(){ var localuri = new Uri(string.Format("https://{0}/Help",RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["httpsIn"].IPEndpoint)); while (true) { try { var request = (httpWebRequest)WebRequest.Create(localuri); request.Method = "GET"; var response = request.GetResponse(); } catch { } System.Threading.Thread.Sleep(3000); }}
(c)在RoleEntryPoint.OnStart()中设置preloadEnabled和startMode
public overrIDe voID OnStart(){ using (var serverManager = new ServerManager()) { foreach (var application in serverManager.Sites.SelectMany(x => x.Applications)) { application["preloadEnabled"] = true; } foreach (var applicationPool in serverManager.ApplicationPools) { applicationPool["startMode"] = "AlwaysRunning"; } serverManager.CommitChanges(); } return base.OnStart();}
(d)最后,使用Azure的“Always On”(编辑:这只是Azure网站不幸!)
我应该执行哪些策略?
解决方法 我们结合了几个这样的答案,它对我们来说是非常好的,但是它们非常快速的改变和测试,似乎覆盖了所有的基础。public overrIDe bool OnStart(){ ServicePointManager.DefaultConnectionlimit = 12; if(!RoleEnvironment.IsEmulated) { using(ServerManager serverManager = new ServerManager()) { foreach (var app in serverManager.Sites.SelectMany(x => x.Applications)) { app["preloadEnabled"] = true; } foreach (var appPool in serverManager.ApplicationPools) { appPool.autoStart = true; appPool["startMode"] = "AlwaysRunning"; appPool.ProcessModel.IDleTimeout = TimeSpan.Zero; appPool.Recycling.PeriodicRestart.Time = TimeSpan.Zero; } serverManager.CommitChanges(); } } return base.OnStart();}总结
以上是内存溢出为你收集整理的Azure Web角色“热身”策略全部内容,希望文章能够帮你解决Azure Web角色“热身”策略所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)