# 耐力测试（软件工程）

耐力测试，又称浸泡测试，是一种软件测试方法，它在持续、典型的负载下长时间运行系统，以发现仅在持续运行中才会出现的问题，例如[内存泄漏](https://www.edgepedia.org/zh/memory-leak)以及性能或可靠性的逐渐退化。ISO/IEC/IEEE 29119-1 将其定义为一种性能效率测试，用于评估测试项能否在指定时间段内持续承受所需负载。<sup>[1](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-1.pdf)</sup> 大多数团队将浸泡测试、耐力测试、稳定性测试和长寿命测试这几个名称互换使用。<sup>[2](https://loadster.com/guides/endurance-testing/)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 在指定时间段内持续承受所需负载的性能效率测试（ISO/IEC/IEEE 29119-1）<sup>[1](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-1.pdf)</sup> |
| 典型时长 | 大约 4 到 72 小时；大多数运行在 8 到 24 小时之间，复杂系统为 48 小时或更长<sup>[3](https://grafana.com/docs/k6/latest/testing-guides/test-types/soak-testing)</sup><sup> • </sup><sup>[4](https://www.mongodb.com/resources/basics/endurance-testing)</sup> |
| 负载水平 | 通常为压力测试上限的 50–80%，或最繁忙典型小时的负载；一些实践者使用预期峰值的 80–90%<sup>[2](https://loadster.com/guides/endurance-testing/)</sup><sup> • </sup><sup>[5](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)</sup> |
| 主要失效模式 | 内存泄漏、连接池耗尽、日志与磁盘增长、文件描述符泄漏、GC 退化<sup>[6](https://yrkan.com/course/module-02-levels-types/stress-endurance-spike-volume-testing/)</sup> |
| 通过标准 | 各项指标的斜率，而非其时间点数值；持续上升的指标可能表明泄漏，但不足以证明存在泄漏，因为正常增长也可能产生正斜率<sup>[7](https://qawerk.com/blog/soak-testing-catches-memory-leaks/)</sup><sup> • </sup><sup>[8](https://loadfocus.com/blog/2026/08/endurance-testing-soak-testing)</sup><sup> • </sup><sup>[17](https://publib.boulder.ibm.com/httpserv/cookbook/Recipes-Troubleshooting_Recipes-Troubleshooting_Memory_Leaks.html)</sup> |
| 常用工具 | Apache JMeter、k6、Gatling、Locust<sup>[9](https://bugbug.io/blog/software-testing/soak-testing/)</sup> |

## 工作原理

短时负载测试问的是某项指标在某一时间点是否可接受；浸泡测试问的是该指标是否正朝危险方向移动。<sup>[10](https://loadtester.org/soak-testing-tool)</sup> 原因在于累积。每次请求泄漏 50 KB 在 1,000 次请求的测试中无法察觉，但在 100,000 次请求后会消耗 5 GB。每 10,000 笔事务泄漏 1 个连接，200 个连接的池在约 200 万笔事务后就会耗尽，在中等吞吐量下大约需要 6–8 小时。<sup>[11](https://www.radview.com/performance_testing/4-types-of-load-testing-and-when-each-should-be-used/)</sup> 每小时增加 1 MB 的缓慢内存泄漏会在数天后使系统崩溃。<sup>[6](https://yrkan.com/course/module-02-levels-types/stress-endurance-spike-volume-testing/)</sup>

信号是趋势，不是数值。内存、活动连接数和响应时间都应各自达到可见的平台期；第 8 小时仍持续上升的趋势意味着运行应延长至 12 或 24 小时。<sup>[11](https://www.radview.com/performance_testing/4-types-of-load-testing-and-when-each-should-be-used/)</sup> 预期中的资源重置（如垃圾回收、缓存逐出或连接回收）没有发生，本身就是一项有用的发现。<sup>[10](https://loadtester.org/soak-testing-tool)</sup>

运行期间监控的指标包括内存使用量、CPU 利用率、响应时间、数据库事务、线程数和日志增长；测试计划必须定义可接受的退化水平以及什么构成失败。<sup>[4](https://www.mongodb.com/resources/basics/endurance-testing)</sup> 需要与性能变化关联的后端资源包括消耗的 RAM、CPU、网络以及云资源的增长。<sup>[3](https://grafana.com/docs/k6/latest/testing-guides/test-types/soak-testing)</sup> 实践者还会观察打开的文件描述符、套接字、数据库、HTTP 和缓存池的连接池利用率、磁盘与日志大小、队列深度，以及延迟和错误率的漂移。<sup>[2](https://loadster.com/guides/endurance-testing/)</sup>

阈值基于趋势：响应时间应保持平稳，内存应达到平台期，错误率应保持为零或其正常底线，吞吐量应在恒定负载下保持稳定。<sup>[8](https://loadfocus.com/blog/2026/08/endurance-testing-soak-testing)</sup> 持续攀升而不进入平台期的指标通常是泄漏。<sup>[2](https://loadster.com/guides/endurance-testing/)</sup>

## 如何实施

工作负载剖面分为三个阶段：逐步增加直至负载达到平均用户数或吞吐量，在明显更长的时间内维持该负载，然后停止或逐渐减少。<sup>[3](https://grafana.com/docs/k6/latest/testing-guides/test-types/soak-testing)</sup> 典型剖面使用 15–30 分钟将负载提升至预期最大容量的 70–80%，4–72 小时的稳态，以及 15–30 分钟的降载。<sup>[6](https://yrkan.com/course/module-02-levels-types/stress-endurance-spike-volume-testing/)</sup>

负载水平在有实测流量数据时据此设定：常见经验法则是压力测试上限的 50–80%，或与最繁忙典型小时流量相匹配的数值。<sup>[2](https://loadster.com/guides/endurance-testing/)</sup> 当平均负载数据不可用时，可在项目团队确认后使用峰值负载的 50%、60% 或 75%。<sup>[12](https://perfmatrix.com/what-is-endurance-test/)</sup> 一些工程团队则按预期峰值负载的 80–90% 运行。<sup>[5](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)</sup>

时长由系统决定，而非惯例。运行应至少跨越系统的一个自然周期，例如每小时批处理作业或每夜备份，并覆盖长时间运行的定时作业的至少一个完整周期。<sup>[8](https://loadfocus.com/blog/2026/08/endurance-testing-soak-testing)</sup><sup> • </sup><sup>[2](https://loadster.com/guides/endurance-testing/)</sup> 时长也可由泄漏检测灵敏度决定：确定生产环境中会有影响的最小每小时堆增长量，然后计算能将这一斜率与 GC 抖动区分开来的最短运行时长。如果每小时 2 MB 在当前窗口内无法与噪声区分，则窗口太短。<sup>[7](https://qawerk.com/blog/soak-testing-catches-memory-leaks/)</sup>

## 起源

没有已发表的文献指出软件耐力测试的创始人、论文或引入年份；最早的形式化定义是 ISO/IEC/IEEE 29119-1 中的定义。<sup>[1](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-1.pdf)</sup> 这一概念在硬件测试中的根源——浸泡测试通过在数月内以等于或高于最大额定值运行电子设备，来检测浴缸曲线上的磨损故障——仅依据一位实践者的记述。<sup>[13](https://www.dodgycoder.net/2012/06/applying-hardware-testing-concepts-to.html)</sup>

## 变体

耐力测试属于性能测试之列，但在目的和时长上有所不同。负载测试检查系统能否处理预期流量，通常运行 15–60 分钟。压力测试确定系统在超出正常容量的极端负载下如何退化与恢复。尖峰测试施加突然、急剧的浪涌然后撤除。浸泡测试在数小时或数天内施加持续负载，以暴露内存泄漏、连接池耗尽和缓慢的资源退化。<sup>[14](https://gatling.io/blog/load-testing-vs-stress-testing)</sup><sup> • </sup><sup>[2](https://loadster.com/guides/endurance-testing/)</sup> 容量测试以正常用户水平针对非常大的数据量进行测试，稳定性测试则在各种条件下变化负载。<sup>[15](https://www.guru99.com/soak-testing.html)</sup>

“浸泡测试”和“耐力测试”在性能工程中互换使用。在团队确实加以区分的地方，耐力测试关注响应时间是否向上漂移，而浸泡测试关注内存、文件句柄和连接池等资源消耗。<sup>[15](https://www.guru99.com/soak-testing.html)</sup>

## 应用

用于长时间浸泡工作负载的常用工具是 [Apache JMeter](https://www.edgepedia.org/zh/apache-jmeter)、k6、Gatling 和 Locust，它们记录响应时间、吞吐量和资源使用情况。<sup>[9](https://bugbug.io/blog/software-testing/soak-testing/)</sup> 推荐使用 k6 或 Locust 等专用框架而非内置功能测试运行器，因为它们能更准确地模拟真实负载场景；浸泡测试能捕获资源耗尽、以内存不足崩溃告终的内存泄漏、GC 异常以及碎片化相关的退化。<sup>[5](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)</sup>

由于浸泡测试运行数小时或数天，它很少作为拉取请求的门禁。团队通常在合并到主分支后运行，并异步消化反馈，在无法实现完整环境隔离时往往每个冲刺运行一次。该测试需要可观测性、指标和追踪才有价值。<sup>[5](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)</sup> 对于 [Kubernetes](https://www.edgepedia.org/zh/kubernetes) 和云应用，建议从多个位置进行分布式负载生成，因为单个客户端无法产生足够的真实流量。<sup>[16](https://oneuptime.com/blog/post/2026-02-09-soak-tests-locust-distributed/view)</sup> 对于 Kubernetes 应用，浸泡测试验证 Pod 保持稳定内存而无泄漏、连接池不会耗尽、磁盘空间保持充足、CPU 使用率保持一致，以及自动扩缩在持续负载下行为正确。<sup>[16](https://oneuptime.com/blog/post/2026-02-09-soak-tests-locust-distributed/view)</sup>

## 局限与替代方案

测试环境必须紧密镜像生产基础设施、系统资源、网络配置和数据库行为；如果差异显著，结果可能无法反映真实使用情况。<sup>[4](https://www.mongodb.com/resources/basics/endurance-testing)</sup> 长时间运行消耗实验室时间和共享环境，这就是浸泡测试按计划安排而非每次变更都运行的原因。<sup>[5](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)</sup>

误报是实际危害。缓存和垃圾回收会产生正常的锯齿状内存模式，因此泄漏检测应将堆、GC 暂停时长、连接池高水位标记和文件描述符数量关联到同一时间轴上。与负载形态转换相关的 GC 暂停时长漂移才是信号，因为平均值会掩盖漂移。<sup>[7](https://qawerk.com/blog/soak-testing-catches-memory-leaks/)</sup> 定量方法每 5 分钟采样 GC 后的堆内存占用低点，并对运行最后 60% 的数据拟合线性回归：如果斜率在 \( p < 0.05 \) 下为正，则可能存在泄漏，不过缓存填充至上限等正常增长也可能产生正斜率。<sup>[7](https://qawerk.com/blog/soak-testing-catches-memory-leaks/)</sup><sup> • </sup><sup>[17](https://publib.boulder.ibm.com/httpserv/cookbook/Recipes-Troubleshooting_Recipes-Troubleshooting_Memory_Leaks.html)</sup> 最后，某些失效模式需要比其他模式更长的窗口：内存泄漏通常在数小时内显现，但日志轮转问题、磁盘写满问题和定时作业积压可能只在数天跨度内才会浮现。<sup>[2](https://loadster.com/guides/endurance-testing/)</sup>

## References

1. [ISO/IEC/IEEE 29119-1, Software and systems engineering, Software testing, Part 1: Concepts and definitions](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-1.pdf)
2. [Soak Testing: Finding Memory Leaks and Slow Burns](https://loadster.com/guides/endurance-testing/)
3. [Soak testing, Grafana k6 documentation](https://grafana.com/docs/k6/latest/testing-guides/test-types/soak-testing)
4. [What Is Endurance Testing and Why Does It Matter for Software? | MongoDB](https://www.mongodb.com/resources/basics/endurance-testing)
5. [Soak Testing as part of SDLC (DraftKings Engineering)](https://medium.com/draftkings-engineering/soak-testing-as-part-of-sdlc-a07b2dbc3fd7)
6. [Stress, Endurance, Spike, Volume Testing (Yrkan course material)](https://yrkan.com/course/module-02-levels-types/stress-endurance-spike-volume-testing/)
7. [Soak Testing: Why 8-Hour Runs Miss Production Leaks | QAwerk](https://qawerk.com/blog/soak-testing-catches-memory-leaks/)
8. [What is Endurance Testing (Soak Testing)? (LoadFocus)](https://loadfocus.com/blog/2026/08/endurance-testing-soak-testing)
9. [What Is Soak Testing (and How to Do It Right) (Bugbug)](https://bugbug.io/blog/software-testing/soak-testing/)
10. [Soak Testing Tool for Long-Run Stability (LoadTester)](https://loadtester.org/soak-testing-tool)
11. [4 Types of Load Testing: Load, Stress, Capacity & Soak Explained](https://www.radview.com/performance_testing/4-types-of-load-testing-and-when-each-should-be-used/)
12. [What is Soak Test | What is Endurance Test | Purpose | Approach (PerfMatrix)](https://perfmatrix.com/what-is-endurance-test/)
13. [Applying hardware testing concepts to software (Dodgy Coder)](https://www.dodgycoder.net/2012/06/applying-hardware-testing-concepts-to.html)
14. [Load testing vs stress testing: key differences (Gatling)](https://gatling.io/blog/load-testing-vs-stress-testing)
15. [Soak Test in Software: Meaning & Examples (Guru99)](https://www.guru99.com/soak-testing.html)
16. [How to Use Soak Tests for Kubernetes Applications (OneUptime)](https://oneuptime.com/blog/post/2026-02-09-soak-tests-locust-distributed/view)
17. [IBM WebSphere Application Server Performance Cookbook - Troubleshooting Memory Leaks](https://publib.boulder.ibm.com/httpserv/cookbook/Recipes-Troubleshooting_Recipes-Troubleshooting_Memory_Leaks.html)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026; Oct 21, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software testing and quality

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/endurance-testing-software-engineering

English original: https://www.edgepedia.org/endurance-testing-software-engineering
