雲端應用程式的效能測試和反模式Performance testing and antipatterns for cloud applications

效能反模式 就像設計模式一樣,都是組織內常見的有問題程式和實施。Performance antipatterns, much like design patterns, are common defective processes and implementations within organizations. 這些是常見的做法,可能會在應用程式受到壓力時導致擴充性問題。These are common practices that are likely to cause scalability problems when an application is under pressure. 認知這些實務有助於簡化軟體專業人員之間的高階概念通訊。Awareness of these practices can help simplify communication of high-level concepts amongst software practitioners.

以下是常見案例:應用程式在效能測試期間行為正常。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 testing is 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 scalability 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.
重試風暴Retry Storm 經常重試伺服器的失敗要求。Retrying failed requests to a server too often.
同步 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