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

云应用程序的性能反模式Performance antipatterns for cloud applications

性能反模式是指在应用程序承受压力时,可能导致可伸缩性问题的某种常见做法。 A performance antipattern is a common practice that is likely to cause scalability problems when an application is under pressure.

下面是一个常见的情景:在测试期间,某个应用程序的行为正常。Here is a common scenario: An application behaves well during performance testing. 然后,该应用程序被发布到生产环境,并开始处理实际工作负荷。It's released to production, and begins to handle real workloads. 从这时起,它开始表现异常—拒绝用户请求、停滞或引发异常。At that point, it starts to perform poorly—rejecting user requests, stalling, or throwing exceptions. 此时,开发团队面临两个问题:The development team is then faced with two questions:

  • 在测试期间为何未发现此行为?Why didn't this behavior show up during testing?
  • 如何解决?How do we fix it?

第一个问题的答案非常简单。The answer to the first question is straightforward. 在测试环境中很难模拟真实的用户、他们的行为模式,以及他们可能需要完成的工作量。It's difficult to simulate real users in a test environment, along with their behavior patterns and the volumes of work they might perform. 了解系统在承受负载时的行为方式的唯一有把握方法是在生产环境中对它进行观察。The only completely sure way to understand how a system behaves under load is to observe it in production. 要澄清的一点是,我们并不建议跳过性能测试。To be clear, we aren't suggesting that you should skip performance testing. 性能测试对于获得基准性能指标至关重要。Performance tests are crucial for getting baseline performance metrics. 但是,必须准备好观察并纠正应用程序在实时系统中出现的性能问题。But you must be prepared to observe and correct performance issues when they arise in the live system.

至于第二个问题 - 如何解决的答案,就不是那么直接。The answer to the second question, how to fix the problem, is less straightforward. 问题可能由或多或少的因素造成,有时,问题只会在特定的条件下出现。Any number of factors might contribute, and sometimes the problem only manifests under certain circumstances. 检测和日志记录对于查找根本原因非常关键,但是,还必须知道要查看哪些信息。Instrumentation and logging are key to finding the root cause, but you also have to know what to look for.

根据与 Microsoft Azure 客户的互动,我们已识别了客户在生产环境中遇到的最常见性能问题。Based on our engagements with Microsoft Azure customers, we've identified some of the most common performance issues that customers see in production. 对于每个反模式,我们介绍了通常出现该反模式的原因、该反模式的症状,以及解决问题的方法。For each antipattern, we describe why the antipattern typically occurs, symptoms of the antipattern, and techniques for resolving the problem. 此外,我们还提供了示例代码用于演示对立模式和建议的解决方法。We also provide sample code that illustrates both the antipattern and a suggested solution.

阅读介绍时,其中一些反模式似乎很明显,但它们出现的次数比想象的更频繁。Some of these antipatterns may seem obvious when you read the descriptions, but they occur more often than you might think. 有时,应用程序继承了本地工作的设计,但无法在云中缩放。Sometimes an application inherits a design that worked on-premises, but doesn't scale in the cloud. 应用程序的设计一开始可能非常干净,但随着新功能的添加,其中一种或多种反模式就会渗入。Or an application might start with a very clean design, but as new features are added, one or more of these antipatterns creeps in. 不管怎样,本指南都可帮助你识别并解决这些反模式。Regardless, this guide will help you to identify and fix these antipatterns.

反模式的目录Catalog of antipatterns

下面是我们已识别的反模式列表:Here is the list of the antipatterns that we've identified:

反模式Antipattern 说明Description
繁忙数据库Busy Database 将过多的处理工作附加到数据存储。Offloading too much processing to a data store.
繁忙前端Busy Front End 将资源密集型任务转移到后台线程。Moving resource-intensive tasks onto background threads.
琐碎 I/OChatty I/O 持续发送许多小型网络请求。Continually sending many small network requests.
超量提取Extraneous Fetching 检索的数据量超过需要,导致不必要的 I/O。Retrieving more data than is needed, resulting in unnecessary I/O.
不当实例化Improper Instantiation 反复创建和销毁原本应该共享并重复使用的对象。Repeatedly creating and destroying objects that are designed to be shared and reused.
单一式持久保存Monolithic Persistence 对采用截然不同的使用模式的数据使用相同的数据存储。Using the same data store for data with very different usage patterns.
无缓存No Caching 无法缓存数据。Failing to cache data.
同步 I/OSynchronous I/O I/O 完成时阻塞调用线程。Blocking the calling thread while I/O completes.

后续步骤Next steps

有关性能优化的详细信息,请参阅对分布式应用程序进行性能优化For more about performance tuning, see Performance tuning a distributed application