简体   繁体   English

持续集成中的性能测试?

[英]Performance testing in continuous integration?

We already have a continuous integration process going where we build, run unit tests, do static code analysis and generate documentation.我们已经有一个持续集成过程,用于构建、运行单元测试、进行静态代码分析和生成文档。 However, we would like expand this to include automatic performance testing.但是,我们希望将其扩展为包括自动性能测试。 In this case, we are working on a .NET web application.在本例中,我们正在开发一个 .NET Web 应用程序。

We have done some performance testing with JMeter (outside the CI process), but I don't know if this is the best tool to include in a CI process?我们已经用 JMeter 做了一些性能测试(在 CI 过程之外),但我不知道这是否是包含在 CI 过程中的最佳工具? Is Selenium an option?硒是一种选择吗? WAPT Pro? WAPT 专业版?

On which levels should we test the performance?我们应该在哪些级别上测试性能? Should we have a set of "performance unit tests"?我们应该有一套“性能单元测试”吗? Should we run JMeter (or something similar) on a production-like environment and fail if any requests takes > 1 second?我们是否应该在类似生产的环境中运行 JMeter(或类似的东西)并在任何请求耗时 > 1 秒时失败? Wouldn't something like this have too high variance?这样的东西不会有太大的差异吗?

So, do you guys include automatic performance testing as part of your CI?那么,你们是否将自动性能测试作为 CI 的一部分? What do you test, and which tools do you use?你测试什么,你使用哪些工具? What has your experience been like?你的经历是怎样的?

First off, JMeter is a good choice for inclusion in CI because it can be run from the command line and you can pass in variables when you do this.首先,JMeter 是包含在 CI 中的不错选择,因为它可以从命令行运行,并且您可以在执行此操作时传入变量。 I would recommend it for this task.我会推荐它来完成这项任务。

In general though, integrating Perf.但总的来说,集成 Perf。 testing into CI is difficult.测试 CI 很困难。 You've already listed many of the reasons why this is so you're already half way there because you understand the limitations.您已经列出了许多原因,所以您已经成功了一半,因为您了解这些限制。 And that's the rub: it IS possible to have Perf.这就是问题所在:Perf 是可能的。 tests in CI but only to a limited extent.在 CI 中进行测试,但仅限于有限的范围。

I think that a good approach follows some of these principles:我认为一个好的方法遵循以下一些原则:

You can't run full load (or soak or capacity) tests in CI, it's not practical.您不能在 CI 中运行全负载(或浸泡或容量)测试,这是不切实际的。 The results are subjective and need human interpretation and it takes time to run the tests.结果是主观的,需要人工解释,运行测试需要时间。 But you can run a simpler, cut down set of tests that measure response times for requests and then you can evaluate these response times either:但是您可以运行一组更简单、更精简的测试来测量请求的响应时间,然后您可以评估这些响应时间:

  • Against an NFR or expected range - Ie.针对 NFR 或预期范围 - 即。 Should be less than 1 sec.应小于 1 秒。
  • Against the previous results - Ie.反对以前的结果 - 即。 Should not deviate more than 10% than the last build.与上次构建的偏差不应超过 10%。

You can also run automated load / perf.您还可以运行自动加载/性能。 tests - at full volume - outside of the build process.测试 - 全量 - 在构建过程之外。 'Semi CI'. '半CI'。 So maybe you could automate a test to run overnight and then check the results in the morning?那么也许您可以自动化测试运行一夜,然后在早上检查结果?

Iterate.迭代。 Just start doing it and getting results and fine tune the tests and how you interpret them over time.只需开始这样做并获得结果并微调测试以及随着时间的推移如何解释它们。 Keep it simple and focus on the areas that appear to be useful.保持简单并专注于看起来有用的领域。 Don't launch with a fanfare, keep it quiet until you have confidence with the process and then start failing builds and telling people about it - initially, you're likely to get lots of false negatives.不要大张旗鼓地启动,保持安静,直到你对这个过程有信心,然后开始构建失败并告诉人们它 - 最初,你可能会得到很多误报。

Instrument your results Do this.检测您的结果执行此操作。 A lot.很多。 CI is all about failing early so if you take that as you end objective then the best way to achieve it is to run tests early and often but the problem with that is you risk getting buried in data. CI 就是尽早失败,因此如果您将其视为最终目标,那么实现它的最佳方法是尽早并经常运行测试,但这样做的问题是您可能会被数据淹没。 So an effective method to crunch the data and present the relevant information helps considerably.因此,一种处理数据并呈现相关信息的有效方法有很大帮助。

You can't automate the whole process down to Red Flag Green Flag - but you should try to get as far down that path as possible.您无法将整个过程自动化到红旗绿旗 - 但您应该尝试尽可能沿着这条路走下去。

Finally, there was a very good talk given by the lead Perf.最后,Perf 负责人进行了精彩的演讲 tester at Google that covers this subject.谷歌的测试人员涵盖了这个主题。 It's a bit old now but the principles still stand.现在有点老了,但原则仍然存在。 Plus, in a few weeks I'm going to a meetup where Channel4, a British media company, will be talking about how they approached this - maybe you can ask for some slides.另外,几周后我将参加一个聚会,届时英国媒体公司 Channel4 将讨论他们如何解决这个问题——也许你可以索要一些幻灯片。

> You can't run full load (or soak or capacity) tests in CI, it's not practical. > 您不能在 CI 中运行满载(或浸泡或容量)测试,这是不切实际的。

After the TISQA conference here in the States this week, I'm more inclined to say that we should confidently be automating more and more of the full, complex load testing with CI automation.本周在美国举行TISQA 会议之后,我更倾向于说我们应该自信地使用 CI 自动化来自动化越来越多的完整、复杂的负载测试。

You might even consider having a separate CI instance running in the larger load testing lab, configured with more realistic infrastructure to support meaningful test results.您甚至可以考虑在更大的负载测试实验室中运行一个单独的 CI 实例,配置更真实的基础设施以支持有意义的测试结果。 The load testing process itself is not unlike a separate software development process (design, construct, deploy, execute, analyze, repeat).负载测试过程本身与单独的软件开发过程(设计、构建、部署、执行、分析、重复)没有什么不同。 Most of every performance tool is now supporting more elegant and robust integrations to CI solutions including SOASTA, LoadRunner/PC, JMeter, Neotys, Blazemeter, Flood.io.大多数性能工具现在都支持与 CI 解决方案的更优雅和强大的集成,包括 SOASTA、LoadRunner/PC、JMeter、Neotys、Blazemeter、Flood.io。

But here's three things to watch out for - similar to Oliver's comments: - there's a lot more nuances to performance results...not just clearly PASS or FAIL - don't forget script maintenance to keep in sync with app changes - synchronizing/scaling your load testing lab with production might also be automated但这里有三件事需要注意 - 类似于 Oliver 的评论: - 性能结果有更多细微差别......不仅仅是明确的通过或失败 - 不要忘记脚本维护以与应用程序更改保持同步 - 同步/缩放您的生产负载测试实验室也可能是自动化的

If you wish - review some of the slides from my own TISQA presentation here .如果您愿意,请在此处查看我自己的 TISQA 演示文稿中的一些幻灯片。 That might be a start on how to use CI + Performance across the entire lifecycle.这可能是如何在整个生命周期中使用 CI + 性能的开始。 Such as, why not have a CI instance that just "watches the configuration" as it gets changed in PROD and sync those changes back to your load test environment?例如,为什么不让 CI 实例在 PROD 中发生更改时“监视配置”并将这些更改同步回您的负载测试环境?

Neither JMeter nor Selenium are tools for CI. JMeter 和 Selenium 都不是 CI 的工具。 JMeter is performance testing tool, Selenium is tool for automated functional testing. JMeter 是性能测试工具,Selenium 是自动化功能测试工具。 So, to have performance testing integrated into build process, you can use JMeter with any of CI servers:Jenkins, Bamdoo, etc.因此,要将性能测试集成到构建过程中,您可以将 JMeter 与任何 CI 服务器一起使用:Jenkins、Bamdoo 等。

AFAIK, there are two common solution of using JMeter with Jenkins nowadays: AFAIK,如今在 Jenkins 中使用 JMeter 有两种常见的解决方案:

  1. Use Jenkins/Hudson with JMeter plugin for it, which allow to start performance testing task after finishing build process.使用带有 JMeter 插件的 Jenkins/Hudson,它允许在完成构建过程后开始性能测试任务。 In this case you need to have appropriate number of load generator with JMeter configured on it.在这种情况下,您需要配置适当数量的负载生成器并在其上配置 JMeter。

  2. Another way - using JMeter testing cloud .另一种方法 - 使用JMeter 测试云 This service provides Jenkins plugin , which allows to start remote test after building application.该服务提供Jenkins 插件,允许在构建应用程序后启动远程测试。 In this case you don't need to care about configuring test servers.在这种情况下,您不需要关心配置测试服务器。

PS While I'm working for Blazemeter, I wanted to provide objective information. PS 当我为 Blazemeter 工作时,我想提供客观的信息。 Hope, it's helpful.希望,很有帮助。

In your question you asked - Is selenium an option?在您提出的问题中 - 硒是一种选择吗?

If you are running from CI utilizing either an internal grid of computers or the public Cloud then you should consider performance testing using Selenium WebDriver with the Headless browser driver.如果您使用内部计算机网格或公共云从 CI 运行,那么您应该考虑使用 Selenium WebDriver 和 Headless 浏览器驱动程序进行性能测试。

On a small Amazon VM (ami) I get around 25 Virtual Users simulated using this approach.在一个小型 Amazon VM (ami) 上,我使用这种方法模拟了大约 25 个虚拟用户。 So, if your needs are in the order of 500 VU's, then I would investigate this as the benefits include:-因此,如果您的需求大约为 500 个 VU,那么我会对此进行调查,因为其好处包括:-

No more 'correlating' for URL re-writing etc. as the headless browser handles this automatically.由于无头浏览器会自动处理 URL 重写等,因此不再需要“关联”。

Your functional tests are repurposed as Performance tests so one tool to become an expert in and no rework just re-purpose.您的功能测试被重新用作性能测试,因此是一种成为专家的工具,无需返工,只需重新调整目的。

You are not the only person looking at integrating performance testing with continuous integration.您并不是唯一一个将性能测试与持续集成相集成的人。 In general, non-funtional testing used to be ignored or left for the very end of software delivery process by a lot of ogranisations.一般来说,非功能性测试过去常常被许多组织忽略或留到软件交付过程的最后阶段。 I can see positive change in the attitude and more interest in automatic verification of non-functional requirements in CI/CD.我可以看到态度的积极变化以及对 CI/CD 中非功能性需求的自动验证的兴趣。 This includes performance, accessibility and security, to different extent.这在不同程度上包括性能、可访问性和安全性。 You've mentioned using Selenium for performance testing.您已经提到使用 Selenium 进行性能测试。 I know some people (try to) do that, and even saw how unsuccessful was one of such attempts.我知道有些人(尝试)这样做,甚至看到这样的尝试之一是多么不成功。 I perfectly understand why people consider doing it, although I'd suggest to stay away from this.我完全理解人们为什么考虑这样做,尽管我建议远离这个。 Unless you have a very good reason to do the opposite.除非你有充分的理由反其道而行之。 In general, it's harder to achieve than one may think.一般来说,实现起来比人们想象的要难。 Selenium is a great tool to include in CI for GUI testing purposes, but its incorporation in performance testing is somewhat troublesome. Selenium 是一个很好的工具,可以包含在 CI 中用于 GUI 测试,但将其纳入性能测试有点麻烦。

There is now a new tool, which can help you integrate JMeter with CI server of your choice, with some dedicated features for TeamCity and Jenkins:现在有一个新工具可以帮助您将 JMeter 与您选择的 CI 服务器集成,并为 TeamCity 和 Jenkins 提供一些专用功能:

https://github.com/automatictester/lightning https://github.com/automatictester/lightning

Feature requests are welcome.欢迎提出功能要求。

If performance is essential part of your application and you care (or want to care) from the beginning and continuously, I'd aim to keep it as a part of the integration and deployment pipeline - so YES.如果性能是您的应用程序的重要组成部分,并且您从一开始就一直关心(或想要关心),我的目标是将其作为集成和部署管道的一部分 - 所以是的。

There are many tools in .NET world (and beyond) which are here to help you to deliver this experience and set it up seamlessly in your favourite CI/CD software eg: .NET 世界(及其他)中有许多工具可以帮助您提供这种体验并在您最喜欢的 CI/CD 软件中无缝设置,例如:

  • k6.io ( https://k6.io/ - previously known as LoadImpact) - allows you to perform performance checks outside of your environment and report it back to the pipeline with results. k6.io ( https://k6.io/ - 以前称为 LoadImpact) - 允许您在环境之外执行性能检查,并将结果报告给管道。 Easy to configure and integrate, great when it comes to more "clever" testing scenarios such as stress tests, load tests etc.易于配置和集成,非常适合更“聪明”的测试场景,例如压力测试、负载测试等。
  • sitespeed.io ( https://www.sitespeed.io/ ) - my 2nd favorite, very fun to use and easy to configure tool to track FE performance and tests (eg done with Selenium) sitespeed.io ( https://www.sitespeed.io/ ) - 我的第二个最爱,使用起来非常有趣且易于配置,用于跟踪 FE 性能和测试的工具(例如使用 Selenium 完成)
  • Locust ( https://locust.io/ ) - for load testing on your own environments. Locust ( https://locust.io/ ) - 用于在您自己的环境中进行负载测试。 Great repo with the ARM template to create your own "farm" of servers on Azure: https://github.com/ORBA/azure-locust使用 ARM 模板在 Azure 上创建您自己的服务器“农场”的绝佳存储库: https : //github.com/ORBA/azure-locust
  • dynatrace ( https://www.dynatrace.com/ ) - fully qualified APM = Application Performance Monitoring/Management tool with a ton of the features and possibilities dynatrace ( https://www.dynatrace.com/ ) - 完全合格的 APM = 具有大量功能和可能性的应用程序性能监控/管理工具
  • Roslyn Analyser (FxCopAnalyzers), StyleCopAnalyzers, EditorConfig and other ways to detect common (also performance-related!) issues in your code even before it's pushed to the build and deployment pipelines Roslyn Analyzer (FxCopAnalyzers)、StyleCopAnalyzers、EditorConfig 和其他方法来检测代码中的常见(也与性能相关!)问题,甚至在代码被推送到构建和部署管道之前
  • Lighthouse Reports - might be also performed as a "pointer" to the most common issues and included as a PR comments eg or notifications during the process (there are many Github Actions or DevOps packages doing it)灯塔报告- 也可以作为最常见问题的“指针”执行,并作为 PR 评论包括在过程中,例如或通知(有许多 Github Actions 或 DevOps 包这样做)

So, yes - all of the above and many more can be placed as a steps on your pipelines.所以,是的 - 以上所有内容以及更多内容都可以作为管道上的步骤。 In our setup, we currently have a whole stage in between of the Staging and UAT environments where we're doing audits: static code analysis, performance tests (FE & BE), security scans and penetration tests (OWASP ZAP) and more.在我们的设置中,我们目前在 Staging 和 UAT 环境之间有一个完整的阶段,我们在其中进行审计:静态代码分析、性能测试 (FE & BE)、安全扫描和渗透测试 (OWASP ZAP) 等等。 If tests are not matching our thresholds or expectations - we obviously don't want to introduce unwanted degradations - we stop here and going back to refactor and fix the issues before reaching UAT & Production.如果测试不符合我们的阈值或期望——我们显然不想引入不必要的降级——我们停在这里并在到达 UAT 和生产之前返回重构和修复问题。 Hope it'll help you and maybe someone else.希望它会帮助你,也许其他人。


I've also gathered some of my findings in my recent talk (slides below) and it converted into the series of blogs around this topics and first of them is already published:我还在最近的演讲(下面的幻灯片)中收集了我的一些发现,并将其转换为围绕该主题的系列博客,其中第一个已经发布:

  1. Slide deck from my talk on "Modern Web Performance Testing": https://slides.com/zajkowskimarcin/modern-web-performance-testing/我关于“​​现代 Web 性能测试”的演讲中的幻灯片: https : //slides.com/zajkowskimarcin/modern-web-performance-testing/
  2. First blog from the series on the same topic: https://wearecogworks.com/blog/the-importance-of-modern-web-performance-testing-part-1同一主题系列的第一篇博客: https : //wearecogworks.com/blog/the-importance-of-modern-web-performance-testing-part-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM