question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spike in CPU usage when iterating over large 'body' object with long timeout.

See original GitHub issue

Current behavior:

Cypress interactive mode is trying things out with long timeouts.

CPU usage goes high and computer becomes warm.

Assumptions: Therefore doing too much on my CPU and network and therefore networks turns off.

https://youtu.be/IIpUElTV1Sk (Unlisted video, only you can see it)

When I kill the Cypress process, wifi turns on by itself.

Desired behavior:

Cypress does handle long timeouts.

It does not overflow the system and therefore does not overuse CPU and network, so that nothing turns itself off.

Test code to reproduce

Versions

MacOS 10.15.3

“cypress-cucumber-preprocessor”: “^2.0.1”, “cypress”: “^4.2.0”,

The timeout length is intentionally set:

{
  "testFiles": "**/*.feature",
  "chromeWebSecurity": false,
  "defaultCommandTimeout": 60000,
  "video": true
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Apr 9, 2020

Setting numTestsKeptInMemory: 0 in the cypress.json may help reduce the CPU usage. I’d suggest doing that to help for now.

I think this is due to a few lines in your test, where you are wrapping over the entire body of an iframe and asserting against the body, with the increasing timeout making the issue worse.

There shouldn’t be a reason to have the commandTimeout : 60000 for this specific .find() command (since you already have the body object, retrying will not change the Object value) - and I’d suggest overwriting it with a lower timeout as a current workaround.

I can recreate a spike in CPU using the following code:

index.html

<!DOCTYPE html>
<html>
<body>
  <iframe src="iframe.html"></iframe>
</body>
</html>

iframe.html

// basically some very large HTML
it("visit example", () => {
  cy.visit("index.html")
  cy.get("iframe")
    .its("0.contentDocument.body").should("not.be.empty")
    .then(cy.wrap)
     // increase timeout to see issue
    .find(".wishlist h6", { timeout: 60000 }) 
    .should("be.visible")
})

Without { timeout: 60000 }

Screen Shot 2020-04-09 at 5 27 43 PM

With { timeout: 60000 }

Screen Shot 2020-04-09 at 5 30 38 PM

Seems to be spending a lot of time on this formatProperty method.

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/chai/inspect.js#L314:L314

0reactions
BlueWindscommented, Dec 21, 2021

This seems closely related to a bug fixed in 9,2, where unnecessary snapshots were being created while retrying commands. In some browsers this manifested as a memory leak followed by the browser crashing or hanging, while in others in caused an unnecessarily large amount of CPU usage, scaling with the size of the page under test.

https://github.com/cypress-io/cypress/issues/18549

A more technical discussion of the causes and resolution of the issue can be found in the PR that closed it: https://github.com/cypress-io/cypress/pull/19311

I’m going close this issue as resolved in 9.2,0 - if anyone involved is still seeing it after updating to that release, please let me know and I’ll reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a CPU spike less than 1 cpu with a bash ...
With a 10% duty cycle, like 1 millisecond running a loop and then calling nanosleep to sleep for 9 milliseconds, you can achieve...
Read more >
CPU spike causing nodes to go irresponsive - Yugabyte
This would cause the node to go unresponsive and any operations like SSH to eventually timeout.
Read more >
How to fix high Java CPU usage problems - TheServerSide.com
CPU usage might skyrocket when your application is under load, but that spike might be attributable to a system process or a misconfiguration...
Read more >
set_time_limit - Manual - PHP
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds...
Read more >
Paginate search results | Elasticsearch Guide [8.5] | Elastic
For deep pages or large sets of results, these operations can significantly increase memory and CPU usage, resulting in degraded performance or node ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found