Windows Azure的或IIS在inital负荷缓慢 [英] windows azure or IIS slow in inital load

查看:192
本文介绍了Windows Azure的或IIS在inital负荷缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Azure中举办了简单的个人MVC4的Web应用程序。

I have a simple personal MVC4 web app that is hosted in Windows Azure.

此Web应用程序在使用非常小,初始呼叫很慢特别是当我试图在早上点击。

This web app is very minimal in use, the initial call is very slow specially when I tried to click in the morning.

我怀疑该IIS是睡觉,而且需要唤醒。我发现这篇文章,并提到这是在IIS中的http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8b3258e7-261c-49a0-888c-0b3e68b2af13这需要在IIS中设置了,但我的web应用程序中的Azure托管,有没有办法做一些在Web.config文件中设置的?

I’m suspecting that the IIS is sleeping and need to wake up. I found this article and mention that this is a bug in IIS http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8b3258e7-261c-49a0-888c-0b3e68b2af13 which required setting up in IIS but my web app is hosted in Azure, is there any way to do some sort of setting in Web.config file?

所有后续调用是快速。

All succeeding calls are fast.

这是我的个人网页。 javierdelacruz.com

Here is my personal page. javierdelacruz.com

感谢。

推荐答案

有两种选择:


  1. 启动任务

  2. 的OnStart code

有关启动任务,请参见此链接

For startup tasks, see this link.

有关的OnStart code,尝试这样的功能(这个功能做了一些事情,太):

For OnStart code, try a function like this (this function does a few more things, too):

    private const string _web_app_project_name = "Web";

    public static void SetupDefaultEgConfiguration(int idleTimeoutInMinutes = 1440, int recycleTimeoutInMinutes = 1440, string appPoolName = "My Azure App Pool", bool enableCompression = true)
    {
        if (!RoleEnvironment.IsEmulated)
        {
            Trace.TraceWarning("Changing IIS settings upon role's OnStart. Inputs: ({0}, {1}, {2}, {3}", idleTimeoutInMinutes, recycleTimeoutInMinutes, appPoolName, enableCompression);

            // Tweak IIS Settings
            using (var iisManager = new ServerManager())
            {
                try
                {
                    var roleSite = iisManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_" + _web_app_project_name];
                    if (enableCompression)
                    {
                        //================ Enable or disable static/Dynamic compression ===================//
                        var config = roleSite.GetWebConfiguration();
                        var urlCompressionSection = config.GetSection("system.webServer/urlCompression");
                        urlCompressionSection["doStaticCompression"] = true;
                        urlCompressionSection["doDynamicCompression"] = true;
                        Trace.TraceWarning("Changing IIS settings to enable static and dynamic compression");
                    }

                    //================ To change ApplicationPool name ================================//
                    var app = roleSite.Applications.First();
                    app.ApplicationPoolName = appPoolName;

                    //================ To change ApplicationPool Recycle Timeout ================================//
                    var appPool = iisManager.ApplicationPools[app.ApplicationPoolName];
                    appPool.Recycling.PeriodicRestart.Time = new TimeSpan(0, recycleTimeoutInMinutes, 0);

                    //================ idletimeout ====================================================//               
                    var defaultIdleTimeout = iisManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout;
                    var newIdleTimeout = new TimeSpan(0, idleTimeoutInMinutes, 0);
                    if ((int)newIdleTimeout.TotalMinutes != (int)defaultIdleTimeout.TotalMinutes)
                    {
                        appPool.ProcessModel.IdleTimeout = newIdleTimeout;
                    }

                    // Commit the changes done to server manager.
                    iisManager.CommitChanges();
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failure when configuring IIS in Azure: " + e.ToString().Take(63000));
                }
            }
        }
    }

<一个href=\"http://blogs.msdn.com/b/sriharsha/archive/2012/04/07/how-to-increase-application-pool-idletimeout-in-windows-azure-cloud-applications.aspx\"相对=nofollow>来源和更多详细信息因为我这里包括功能 - 有一些依赖,你可能会需要做到这一点。

Source and some more details for the function I included here - there are some dependencies you'll likely need to accomplish this.

这篇关于Windows Azure的或IIS在inital负荷缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆