您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 中的 Web 应用的应用程序性能常见问题解答Application performance FAQs for Web Apps in Azure

备注

下面的某些准则可能仅适用于 Windows 或 Linux 应用服务。Some of the below guidelines might only work on Windows or Linux App Services. 例如, 默认情况下, Linux 应用服务在64位模式下运行。For example, Linux App Services run in 64-bit mode by default.

本文包含有关针对 Azure 应用服务的 Web 应用功能的应用程序性能问题的常见问题 (FAQ) 解答。This article has answers to frequently asked questions (FAQs) about application performance issues for the Web Apps feature of Azure App Service.

如果本文未解决 Azure 问题,请访问 MSDN 和 Stack Overflow 上的 Azure 论坛。If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and Stack Overflow. 可将问题发布到这些论坛上,或发布到 Twitter 上的 @AzureSupportYou can post your issue in these forums, or post to @AzureSupport on Twitter. 还可提交 Azure 支持请求。You also can submit an Azure support request. 若要提交支持请求,请在 Azure 支持页上,选择“获取支持” 。To submit a support request, on the Azure support page, select Get support.

为何我的应用速度缓慢?Why is my app slow?

有多个因素可能会导致应用性能减慢。Multiple factors might contribute to slow app performance. 有关详细故障排除步骤,请参阅 Web 应用性能缓慢故障排除For detailed troubleshooting steps, see Troubleshoot slow web app performance.

如何对高 CPU 使用率情况进行故障排除?How do I troubleshoot a high CPU-consumption scenario?

在某些高 CPU 使用率情况下,应用可能的确需要更多计算资源。In some high CPU-consumption scenarios, your app might truly require more computing resources. 在这种情况下,请考虑扩展到较高服务层级,以便应用程序可获取所需的所有资源。 In that case, consider scaling to a higher service tier so the application gets all the resources it needs. 在其他时候,错误循环或编码做法可能会导致高 CPU 使用率。Other times, high CPU consumption might be caused by a bad loop or by a coding practice. 深入了解触发 CPU 使用率提高的因素是包含两个部分的过程。Getting insight into what's triggering increased CPU consumption is a two-part process. 首先,创建一个进程转储,然后分析该进程转储。First, create a process dump, and then analyze the process dump. 有关详细信息,请参阅针对 Web 应用的高 CPU 使用率捕获和分析转储文件For more information, see Capture and analyze a dump file for high CPU consumption for Web Apps.

如何对高内存使用率情况进行故障排除?How do I troubleshoot a high memory-consumption scenario?

在某些高内存使用率情况下,应用可能的确需要更多计算资源。In some high memory-consumption scenarios, your app might truly require more computing resources. 在这种情况下,请考虑扩展到较高服务层级,以便应用程序可获取所需的所有资源。 In that case, consider scaling to a higher service tier so the application gets all the resources it needs. 在其他时候,代码中的 bug 可能会导致内存泄漏。Other times, a bug in the code might cause a memory leak. 编码做法也可能会提高内存使用率。A coding practice also might increase memory consumption. 深入了解触发高内存使用率的因素是包含两个部分的过程。 Getting insight into what's triggering high memory consumption is a two-part process. 首先,创建进程转储,然后分析此进程转储。First, create a process dump, and then analyze the process dump. Azure 站点扩展库中的故障诊断程序可以高效地执行这两个步骤。Crash Diagnoser from the Azure Site Extension Gallery can efficiently perform both these steps. 有关详细信息,请参阅针对 Web 应用的间歇性高内存使用率捕获和分析转储文件For more information, see Capture and analyze a dump file for intermittent high memory for Web Apps.

如何使用 PowerShell 自动执行应用服务 Web 应用?How do I automate App Service web apps by using PowerShell?

可以使用 PowerShell cmdlet 管理和维护应用服务 Web 应用。You can use PowerShell cmdlets to manage and maintain App Service web apps. 在我们的博客文章使用 PowerShell 自动执行在 Azure 应用服务中承载的 Web 应用中,我们介绍了如何使用基于 Azure 资源管理器的 PowerShell cmdlet 自动执行常见任务。In our blog post Automate web apps hosted in Azure App Service by using PowerShell, we describe how to use Azure Resource Manager-based PowerShell cmdlets to automate common tasks. 该博客文章还包含针对各种 Web 应用管理任务的示例代码。The blog post also has sample code for various web apps management tasks. 有关所有应用服务 Web 应用 cmdlet 的说明和语法,请参阅 Az.WebsitesFor descriptions and syntax for all App Service web apps cmdlets, see Az.Websites.

如何查看 Web 应用的事件日志?How do I view my web app's event logs?

查看 Web 应用的事件日志:To view your web app's event logs:

  1. 登录到 Kudu 网站Sign in to your Kudu website.
  2. 在菜单中,选择“调试控制台” > “CMD”。In the menu, select Debug Console > CMD.
  3. 选择 LogFiles 文件夹。Select the LogFiles folder.
  4. 若要查看事件日志,请选择 eventlog.xml 旁的铅笔图标。To view event logs, select the pencil icon next to eventlog.xml.
  5. 若要下载日志,请运行 PowerShell cmdlet Save-AzureWebSiteLog -Name webappnameTo download the logs, run the PowerShell cmdlet Save-AzureWebSiteLog -Name webappname.

如何捕获 Web 应用的用户模式内存转储?How do I capture a user-mode memory dump of my web app?

捕获 Web 应用的用户模式内存转储:To capture a user-mode memory dump of your web app:

  1. 登录到 Kudu 网站Sign in to your Kudu website.
  2. 选择“进程资源管理器”菜单。Select the Process Explorer menu.
  3. 右键单击 w3wp.exe 进程或 Web 作业进程。Right-click the w3wp.exe process or your WebJob process.
  4. 选择“下载内存转储” > “完全转储”。Select Download Memory Dump > Full Dump.

如何查看 Web 应用的进程级信息?How do I view process-level info for my web app?

有两个选项可用于查看 Web 应用的进程级信息:You have two options for viewing process-level information for your web app:

  • 在 Azure 门户中:In the Azure portal:
    1. 打开 Web 应用的“进程资源管理器”。Open the Process Explorer for the web app.
    2. 若要查看详细信息,请选择 w3wp.exe 进程。To see the details, select the w3wp.exe process.
  • 在 Kudu 控制台中:In the Kudu console:
    1. 登录到 Kudu 网站Sign in to your Kudu website.
    2. 选择“进程资源管理器”菜单。Select the Process Explorer menu.
    3. 对于 w3wp.exe 进程,选择“属性”。For the w3wp.exe process, select Properties.

当我浏览到我的应用时,看到“错误 403 - 此 Web 应用已停止”。When I browse to my app, I see "Error 403 - This web app is stopped." 如何解决此问题?How do I resolve this?

有三种状况可能会导致此错误:Three conditions can cause this error:

  • Web 应用已达到计费限制,站点已禁用。The web app has reached a billing limit and your site has been disabled.
  • 在门户中停止了 Web 应用。The web app has been stopped in the portal.
  • Web 应用已达到可能应用于免费或共享缩放服务计划的资源配额限制。The web app has reached a resource quota limit that might apply to a Free or Shared scale service plan.

若要了解导致错误的原因并解决问题,请按照 Web 应用:“错误 403 - 此 Web 应用已停止”中的步骤执行。To see what is causing the error and to resolve the issue, follow the steps in Web Apps: "Error 403 – This web app is stopped".

我可以在何处详细了解各种应用服务计划的配额和限制?Where can I learn more about quotas and limits for various App Service plans?

有关配额和限制的信息,请参阅应用服务限制For information about quotas and limits, see App Service limits.

如何减少空闲时间之后第一个请求的响应时间?How do I decrease the response time for the first request after idle time?

默认情况下,Web 应用如果已处于空闲状态达到一定时间,则会卸载。By default, web apps are unloaded if they are idle for a set period of time. 这样可以让系统节省资源。This way, the system can conserve resources. 其缺点是 Web 应用卸载之后的第一个请求的响应时间会较长,以使 Web 应用可以加载并启动服务响应。The downside is that the response to the first request after the web app is unloaded is longer, to allow the web app to load and start serving responses. 在基本和标准服务计划中,可以打开“始终可用”设置以使应用始终加载。In Basic and Standard service plans, you can turn on the Always On setting to keep the app always loaded. 这可消除应用处于空闲状态之后的较长加载时间。This eliminates longer load times after the app is idle. 更改“始终可用”设置:To change the Always On setting:

  1. 在 Azure 门户中,转到你的 Web 应用。In the Azure portal, go to your web app.
  2. 选择“应用程序设置”。Select Application settings.
  3. 对于“始终可用”,选择“打开”。For Always On, select On.

如何打开失败请求跟踪?How do I turn on failed request tracing?

打开失败请求跟踪:To turn on failed request tracing:

  1. 在 Azure 门户中,转到你的 Web 应用。In the Azure portal, go to your web app.

  2. 选择“所有设置” > “诊断日志”。Select All Settings > Diagnostics Logs.

  3. 对于“失败请求跟踪”,选择“打开”。For Failed Request Tracing, select On.

  4. 选择保存Select Save.

  5. 在 Web 应用边栏选项卡,选择“工具”。On the web app blade, select Tools.

  6. 选择“Visual Studio Online”。Select Visual Studio Online.

  7. 如果设置不是“打开”,则选择“打开”。If the setting is not On, select On.

  8. 选择“转到”。Select Go.

  9. 选择 Web.configSelect Web.config.

  10. 在 system.webServer 中,添加此配置(用于捕获特定 URL):In system.webServer, add this configuration (to capture a specific URL):

    <system.webServer>
    <tracing> <traceFailedRequests>
    <remove path="*api*" />
    <add path="*api*">
    <traceAreas>
    <add provider="ASP" verbosity="Verbose" />
    <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
    <add provider="ISAPI Extension" verbosity="Verbose" />
    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression, Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
    </traceAreas>
    <failureDefinitions statusCodes="200-999" />
    </add> </traceFailedRequests>
    </tracing>
    
  11. 若要对性能缓慢问题进行故障排除,请添加此配置(如果捕获请求时间超过 30 秒):To troubleshoot slow-performance issues, add this configuration (if the capturing request is taking more than 30 seconds):

    <system.webServer>
    <tracing> <traceFailedRequests>
    <remove path="*" />
    <add path="*">
    <traceAreas> <add provider="ASP" verbosity="Verbose" />
    <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
    <add provider="ISAPI Extension" verbosity="Verbose" />
    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression, Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
    </traceAreas>
    <failureDefinitions timeTaken="00:00:30" statusCodes="200-999" />
    </add> </traceFailedRequests>
    </tracing>
    
  12. 若要下载失败请求跟踪,请在门户中,转到你的网站。To download the failed request traces, in the portal, go to your website.

  13. 选择“工具” > “Kudu” > “转到”。Select Tools > Kudu > Go.

  14. 在菜单中,选择“调试控制台” > “CMD”。In the menu, select Debug Console > CMD.

  15. 选择 LogFiles 文件夹,然后选择名称以 W3SVC 开头的文件夹。Select the LogFiles folder, and then select the folder with a name that starts with W3SVC.

  16. 若要查看 XML 文件,请选择铅笔图标。To see the XML file, select the pencil icon.

我看到消息“请求的工作进程由于‘内存百分比’限制而回收”。I see the message "Worker Process requested recycle due to 'Percent Memory' limit." 如何解决此问题?How do I address this issue?

32 位进程的最大可用内存量(即使是在 64 位操作系统上)是 2 GB。The maximum available amount of memory for a 32-bit process (even on a 64-bit operating system) is 2 GB. 默认情况下,工作进程在应用服务中设置为 32 位(以便与旧 Web 应用程序兼容)。By default, the worker process is set to 32-bit in App Service (for compatibility with legacy web applications).

可考虑切换为 64 位进程,以便可以利用 Web 辅助角色中可用的额外内存。Consider switching to 64-bit processes so you can take advantage of the additional memory available in your Web Worker role. 这会触发 Web 应用重新启动,因此请相应地进行计划。This triggers a web app restart, so schedule accordingly.

另请注意,64 位环境需要基本或标准服务计划。Also note that a 64-bit environment requires a Basic or Standard service plan. 免费和共享计划始终在 32 位环境中运行。Free and Shared plans always run in a 32-bit environment.

有关详细信息,请参阅在应用服务中配置 Web 应用For more information, see Configure web apps in App Service.

为何我的请求在 230 秒后超时?Why does my request time out after 230 seconds?

Azure 负载均衡器的默认空闲超时设置为四分钟。Azure Load Balancer has a default idle timeout setting of four minutes. 这通常是针对 Web 请求的合理响应时间限制。This is generally a reasonable response time limit for a web request. 如果你的 Web 应用需要后台处理,则建议使用 Azure Web 作业。If your web app requires background processing, we recommend using Azure WebJobs. Azure Web 应用可以调用 Web 作业,并在后台处理完成时收到通知。The Azure web app can call WebJobs and be notified when background processing is finished. 可以在多种 Web 作业使用方法(包括队列和触发器)中进行选择。You can choose from multiple methods for using WebJobs, including queues and triggers.

Web 作业旨在用于后台处理。WebJobs is designed for background processing. 可以在 Web 作业中根据需要执行后台处理。You can do as much background processing as you want in a WebJob. 有关 Web 作业的详细信息,请参阅使用 Web 作业运行后台任务For more information about WebJobs, see Run background tasks with WebJobs.

在应用服务中承载的 ASP.NET Core 应用程序有时会停止响应。ASP.NET Core applications that are hosted in App Service sometimes stop responding. 如何修复此问题?How do I fix this issue?

与早期 Kestrel 版本有关的一个已知问题可能会在应用服务中承载的 ASP.NET Core 1.0 应用间歇性停止响应。A known issue with an earlier Kestrel version might cause an ASP.NET Core 1.0 app that's hosted in App Service to intermittently stop responding. 还可能会看到以下消息:“指定的 CGI 应用程序遇到错误,服务器终止了该进程”。You also might see this message: "The specified CGI Application encountered an error and the server terminated the process."

在 Kestrel 版本 1.0.2 中已修复了此问题。This issue is fixed in Kestrel version 1.0.2. 此版本包含在 ASP.NET Core 1.0.3 更新中。This version is included in the ASP.NET Core 1.0.3 update. 若要解决此问题,请确保将应用依赖关系更新为使用 Kestrel 1.0.2。To resolve this issue, make sure you update your app dependencies to use Kestrel 1.0.2. 或者,可以使用博客文章应用服务 Web 应用中的 ASP.NET Core 1.0 性能缓慢问题中介绍的两个解决方法之一。Alternatively, you can use one of two workarounds that are described in the blog post ASP.NET Core 1.0 slow perf issues in App Service web apps.

我在我的 Web 应用文件结构中找不到日志文件。I can't find my log files in the file structure of my web app. 如何才能找到它们?How can I find them?

如果使用应用服务的本地缓存功能,则应用服务实例的日志文件和数据文件夹的文件夹结构会受影响。If you use the Local Cache feature of App Service, the folder structure of the LogFiles and Data folders for your App Service instance are affected. 使用本地缓存时,会在存储日志文件和数据文件夹中创建子文件夹。When Local Cache is used, subfolders are created in the storage LogFiles and Data folders. 子文件夹使用命名模式“唯一标识符”+ 时间戳。The subfolders use the naming pattern "unique identifier" + time stamp. 每个子文件夹都对应于一个 VM 实例,其中的 Web 应用正在运行或已运行。Each subfolder corresponds to a VM instance in which the web app is running or has run.

若要确定是否在使用本地缓存,请检查应用服务“应用程序设置”选项卡。如果使用本地缓存,则应用设置 WEBSITE_LOCAL_CACHE_OPTION 设置为 AlwaysTo determine whether you are using Local Cache, check your App Service Application settings tab. If Local Cache is being used, the app setting WEBSITE_LOCAL_CACHE_OPTION is set to Always.

如果未使用本地缓存并且遇到此问题,请提交支持请求。If you are not using Local Cache and are experiencing this issue, submit a support request.

我看到消息“以一种访问权限不允许的方式做了一个访问套接字的尝试”。I see the message "An attempt was made to access a socket in a way forbidden by its access permissions." 如何解决此问题?How do I resolve this?

如果 VM 实例上的出站 TCP 连接耗尽,通常会发生此错误。This error typically occurs if the outbound TCP connections on the VM instance are exhausted. 在应用服务中,会对可以为每个 VM 实例进行的最大出站连接数实施限制。In App Service, limits are enforced for the maximum number of outbound connections that can be made for each VM instance. 有关详细信息,请参阅跨 VM 数值限制For more information, see Cross-VM numerical limits.

如果尝试从应用程序访问本地地址,也可能会发生此错误。This error also might occur if you try to access a local address from your application. 有关详细信息,请参阅本地地址请求For more information, see Local address requests.

有关 Web 应用中的出站连接的详细信息,请参阅有关到 Azure 网站的传出连接的博客文章。For more information about outbound connections in your web app, see the blog post about outgoing connections to Azure websites.

如何使用 Visual Studio 远程调试应用服务Web 应用?How do I use Visual Studio to remote debug my App Service web app?

有关演示如何使用 Visual Studio 调试 Web 应用的详细演练,请参阅远程调试应用服务 Web 应用For a detailed walkthrough that shows you how to debug your web app by using Visual Studio, see Remote debug your App Service web app.