优化内容驱动型 Web 应用的后端性能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对于任何类型的扩缩,请考虑应用的架构以及可以进行哪些优化。例如,静态内容应由经过优化的内容分发网络传送,能够提供价格和性能优势。为数据存储后端额外缓存也有可能提高性能,并最大限度地减少对代价高昂的扩缩的要求。
基准化分析和性能测试可以识别开发过程中的潜在性能瓶颈,帮助跟踪一段时间内的趋势,并通过比较架构、技术栈、云服务商或其他选项来支持决策。
负载测试使用预定的受控类型的负载、流量或数据,来衡量后端针对目标的性能。您可以了解各种负载水平对应用性能的影响。
可伸缩性测试侧重于分析应用的扩容和横向扩容能力。可伸缩性测试会显示应用如何响应增加的负载以及后端(包括数据存储)的调整方式。
在开始对应用进行基准测试之前,定义明确的目标,包括性能和速度(例如延迟时间、吞吐量、速度)、资源利用率(CPU 利用率、内存用量、后端组件之间的网络流量)和费用。考虑扩缩方面的任何延迟;例如,当流量激增或流量激增时,应用扩容时需要超出指定的一组“预留”资源。
许多工具可用于基准化分析和性能测试,例如 Apache JMeter 和 Locust。选择测试工具时,请考虑可用的测试类型,包括您是否需要支持脚本、用于调试的 IDE 集成、其他插件,或者是否支持要测试的流量类型和规模。
如果使用云服务商,请确定是否存在任何负载测试的额外要求或最佳实践,以避免潜在的限制。例如,请考虑 Cloud Run 的最佳实践。
虽然纵向扩容对于提升性能至关重要,但为了最大限度地降低费用,纵向扩容也是一个考虑因素。考虑无任何请求的后端应用的基准费用以及应用纵向扩容所涉及的费用。
无论利用率如何,本地或基于服务器的架构可能都有固定的费用。某些云环境允许您“缩减至零”以避免未发出请求时产生的费用。云服务提供商提供计算器,可用于探索不同的配置和价格策略,例如资源的预承诺。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):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."]]