針對內容導向的網頁應用程式最佳化後端效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
針對任何類型的資源調度,請考慮應用程式的架構和可能的最佳化方式。舉例來說,靜態內容應透過最佳化內容傳遞聯播網提供,因為這類聯播網可以提供價格和效能優勢。額外的資料儲存空間後端快取也可以改善效能,並盡量減少昂貴的資源調度需求。
基準測試和效能測試可協助您找出開發期間的潛在效能瓶頸、協助追蹤長期趨勢,並藉由比較架構、技術堆疊、雲端服務供應商或其他選項來支援決策。
負載測試會使用預先定義且控制的負載、流量或資料,依據目標測量後端的效能。您可以看到各種負載層級對應用程式效能的影響。
擴充性測試的重點在於分析應用程式向上擴充和向外擴充的能力。擴充性測試會顯示應用程式如何因應增加的負載,以及後端 (包括資料儲存空間) 進行調整的方式。
在開始對應用程式進行基準測試前,請先定義明確的目標,其中包括效能和速度 (例如延遲時間、處理量、速度)、資源使用率 (CPU 使用率、記憶體用量、後端元件之間的網路流量) 和成本。考量資源調度時出現的任何延遲情形;例如,當流量突然增加或激增時,應用程式需要擴充的規模,超過分配的「預留」資源組合規模。
許多工具都可用於基準化和效能測試,例如 Apache JMeter 和 Locust。選擇測試工具時,請考慮可用的測試類型,包括是否需要支援指令碼、IDE 整合來進行偵錯、其他外掛程式,或是否支援要測試的流量和規模。
如果您使用雲端服務供應商,請判斷是否有任何負載測試是否有任何額外要求或最佳做法,以免受到潛在限制。例如,考慮 Cloud Run 的最佳做法。
雖然向上擴充是提升效能的關鍵,但縮減規模也應該考慮縮減資源,以盡可能降低成本。請在不發出任何要求的情況下,考量後端應用程式的基本成本,以及擴充應用程式所需的費用。
無論使用率為何,地端部署或伺服器型架構的費用可能固定不變。部分雲端環境可讓您「擴充至零」,避免未發出任何要求時產生的費用。雲端服務供應商提供的計算機可讓您探索不同的設定和定價策略,例如資源的使用前承諾使用合約。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eOptimize application architecture and utilize content delivery networks for static content to enhance performance and minimize scaling needs.\u003c/p\u003e\n"],["\u003cp\u003eBenchmarking and performance testing, including load and scalability testing, are crucial for identifying bottlenecks, tracking performance trends, and making informed decisions about scaling approaches.\u003c/p\u003e\n"],["\u003cp\u003eEstablish clear performance targets, encompassing speed, resource utilization, and cost, and account for potential scaling delays when planning your infrastructure.\u003c/p\u003e\n"],["\u003cp\u003eManage costs by scaling down resources when they are not needed, leveraging cloud provider tools to explore pricing strategies and potentially scaling to zero to minimize expenses during periods of inactivity.\u003c/p\u003e\n"]]],["Application architecture should be optimized for scaling, such as using content delivery networks for static content and caching for data storage. Benchmarking and performance testing, including load and scalability tests, are crucial for identifying bottlenecks. Define targets for performance, resource utilization, and cost. Choose testing tools like Apache JMeter or Locust, considering test types and provider requirements. Balance scaling up for performance with scaling down to minimize costs, exploring cloud options like \"scale to zero.\"\n"],null,["# Optimize backend performance for content-driven web apps\n\nFor any type of scaling, consider the architecture of your application and what\noptimizations may be possible. For example, [static content should be served\nfrom optimized content delivery networks](/solutions/content-driven/hosting/cdn)\nthat offer price and performance benefits. Additional [caching for the data\nstorage\nbackend](/solutions/content-driven/data-storage/performance-optimization#cache)\nmay also improve performance and minimize the requirements for expensive\nscaling.\n\nPerformance testing and benchmarks\n----------------------------------\n\nBenchmarking and performance testing can identify potential performance\nbottlenecks during development, help track trends over time, and support\ndecision making by comparing architectures, technology stacks, cloud providers,\nor other options.\n\n**Load testing** uses predetermined, controlled types of load, traffic, or data\nto measure the performance of your backend against your targets. You can see how\nvarious load levels impact your application's performance.\n\n**Scalability testing** focuses on analyzing your application's ability to\n[scale up and scale out](/solutions/content-driven/backend/scaling). Scalability\ntesting shows how your application responds to increased loads and how the\nbackend (including data storage) adapts.\n\nDefine clear targets before beginning to benchmark the application, including\nperformance and speed (for example latency, throughput, speed), resource\nutilization (CPU utilization, memory usage, network traffic between backend\ncomponents), and cost. Consider any delays in scaling; for example, if the\napplication needs to scale beyond an allocated set of \"reserve\" resources when\nbursts or spikes in traffic occur.\n\nMany tools are available for benchmarking and performance testing, such as\n[Apache JMeter](https://jmeter.apache.org/) and\n[Locust](https://locust.io/). When selecting a testing tool,\nconsider the types of tests that are available, including whether or not you\nneed support for scripting, IDE integrations for debugging, additional plug-ins,\nor support for the kind of traffic and scale to be tested.\n\nIf using a cloud provider, determine if there are any additional requirements or\nbest practices for any load testing to avoid potential restrictions. For\nexample, consider the best practices for [Cloud\nRun](https://cloud.google.com/run/docs/about-load-testing).\n\nCost and performance considerations\n-----------------------------------\n\nWhile scaling up is essential to improve performance, scaling down should also\nbe a consideration to minimize cost. Consider the baseline cost of your backend\napplication without any requests and the cost involved in scaling up the\napplication.\n\nYou may have fixed costs for on-premise or server-based architectures,\nregardless of utilization. Some cloud environments allow you to *\"scale to\nzero\"* to avoid costs when no requests are made. Cloud providers offer\ncalculators for you to explore different configurations and pricing strategies,\nsuch as pre-commitments for resources."]]