Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve memory management for chromium-based browsers #25462

Merged
merged 103 commits into from
Jan 18, 2023
Merged
Changes from 1 commit
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
d0e5c11
call CDP HeapProfiler.collectGarbage
mschile Dec 14, 2022
ef708cf
update circleci
mschile Dec 14, 2022
eec6da5
update version
mschile Dec 14, 2022
dc25317
saving binaries
mschile Dec 14, 2022
5ccc7c6
add browser check
mschile Dec 14, 2022
823648a
getting more metrics
mschile Dec 17, 2022
32aa246
add pidusage
mschile Dec 19, 2022
dfa8fd2
adding experimental flag
mschile Dec 19, 2022
d82c599
adding child top process
mschile Dec 20, 2022
3c9ad8b
updates
mschile Dec 20, 2022
5109e0a
update workflow.yml
mschile Dec 20, 2022
6004ed6
workflow updates
mschile Dec 20, 2022
8a5e1cc
workflow updates [run ci]
mschile Dec 20, 2022
c196247
fixing indentation [run ci]
mschile Dec 20, 2022
c3aeb6a
try again
mschile Dec 20, 2022
6585a30
workflow update
mschile Dec 20, 2022
0c76aee
remove child process
mschile Dec 20, 2022
6cfc7fa
updating folder structure
mschile Dec 20, 2022
9b48ca4
created cdp/memory
mschile Dec 20, 2022
3f9546b
updates
mschile Dec 21, 2022
ebafa9f
require path fix
mschile Dec 21, 2022
b4be5eb
updates
mschile Dec 21, 2022
4a69706
updates
mschile Dec 21, 2022
bc948f2
use cgroup
mschile Dec 21, 2022
18cc4d8
use available memory
mschile Dec 21, 2022
aef4426
updates
mschile Dec 22, 2022
1672914
update workflow [run ci]
mschile Dec 22, 2022
02cc51c
use groupCyProcesses
mschile Dec 22, 2022
7d55e99
add memory stats
mschile Dec 22, 2022
bb50d7d
update to exclude total_inactive_file
mschile Dec 22, 2022
225ce0c
adding checkAndCollectGcDuration
mschile Dec 22, 2022
eb77493
updating max available calc
mschile Dec 22, 2022
88f9fac
50% [run ci]
mschile Dec 22, 2022
54b8904
75% [run ci]
mschile Dec 22, 2022
f3baf0b
updates
mschile Dec 23, 2022
62e3ebc
performance
mschile Dec 23, 2022
2359014
split out files
mschile Dec 23, 2022
e52d309
update async [run ci]
mschile Dec 24, 2022
3bf079b
update num of tests [run ci]
mschile Dec 24, 2022
ee5961c
fix number [run ci]
mschile Dec 24, 2022
c0319b8
update workflows
mschile Dec 24, 2022
9719310
fix async [run ci]
mschile Dec 24, 2022
1d226fc
updating to v1 [run ci]
mschile Dec 24, 2022
54ab986
update message
mschile Dec 24, 2022
dc221f0
updates
mschile Dec 27, 2022
83c9fdb
revert changes
mschile Dec 27, 2022
1ff6969
adding a few additional log fields [run ci]
mschile Jan 3, 2023
fd2624a
additional fields
mschile Jan 3, 2023
4b635af
additional fields
mschile Jan 3, 2023
9f71246
update parallelism
mschile Jan 3, 2023
69c8b72
adding specs
mschile Jan 4, 2023
a220054
updating debug logs
mschile Jan 4, 2023
e897905
adding CYPRESS_INTERNAL_FORCE_GC
mschile Jan 4, 2023
01d40fb
adding CYPRESS_MEMORY_THRESHOLD_PERCENTAGE
mschile Jan 4, 2023
2703be7
updating file writing
mschile Jan 4, 2023
3dd0b76
update naming
mschile Jan 4, 2023
f8f3428
adding darwin and windows
mschile Jan 4, 2023
80379e4
adding test items to log
mschile Jan 5, 2023
0dcbdf3
updating getJsHeapSizeLimit
mschile Jan 5, 2023
27d522a
save artifacts
mschile Jan 5, 2023
0ff89c5
lint fix [run ci]
mschile Jan 6, 2023
565761e
updates
mschile Jan 7, 2023
a725e51
update to use polling
mschile Jan 11, 2023
0f7ee7a
updating specs
mschile Jan 12, 2023
de74f52
updating endProfiling
mschile Jan 12, 2023
e973fa3
updating workflow [run ci]
mschile Jan 12, 2023
31b9a8e
performanceObserver
mschile Jan 12, 2023
e5cf39b
updating flag unit tests, adding back all testing [run ci]
mschile Jan 12, 2023
20ab7ce
reverting to previous sinon version [run ci]
mschile Jan 12, 2023
bc2d1ea
adding back timings [run ci]
mschile Jan 13, 2023
ab6d983
update measuring [run ci]
mschile Jan 13, 2023
e6dcb1b
adding durations to outputted stats [run ci]
mschile Jan 13, 2023
b1414c2
Merge branch 'develop' into mschile/chrome_memory_fix
mschile Jan 13, 2023
a9de0a6
removing test specs [run ci]
mschile Jan 13, 2023
b3b6b2d
Merge branch 'develop' into mschile/chrome_memory_fix
mschile Jan 13, 2023
c90abe7
updating a couple tests
mschile Jan 14, 2023
ea8c574
update retry snapshot [run ci]
mschile Jan 14, 2023
7826546
adding memory driver tests
mschile Jan 14, 2023
48bc2fc
update workflows.yml [run ci]
mschile Jan 14, 2023
51b4c59
installing missing dependency [run ci]
mschile Jan 14, 2023
f405ae9
fixing script path
mschile Jan 15, 2023
5507f19
adding documentation
mschile Jan 16, 2023
6a563b3
adding additional endProfiling
mschile Jan 16, 2023
c7cb319
updating workflow
mschile Jan 16, 2023
1c08b8e
updating workflow
mschile Jan 16, 2023
e4adebe
lint fixes
mschile Jan 17, 2023
d0daff0
fixing circular dependency [run ci]
mschile Jan 17, 2023
fd3c6cc
Apply suggestions from code review
mschile Jan 17, 2023
47476a6
create a few consts [run ci]
mschile Jan 17, 2023
c115b36
fix issue when closing browser
mschile Jan 17, 2023
2cdaace
fixing spec [run ci]
mschile Jan 17, 2023
6541f7d
readability
mschile Jan 17, 2023
6b7ca6a
fix snapshot
mjhenkes Jan 17, 2023
fdd2253
fixing trash spec
mschile Jan 17, 2023
04b9668
updating debugging
mschile Jan 17, 2023
5af89b0
update finding renderer process
mschile Jan 17, 2023
0a00475
update naming, add try/catch
mschile Jan 18, 2023
9e7ee14
renaming to check:memory:pressure
mschile Jan 18, 2023
c9f89aa
Merge branch 'develop' into mschile/chrome_memory_fix
mschile Jan 18, 2023
0676a13
verifying memory stats
mschile Jan 18, 2023
db07f0a
fix fake timer issue in spec
mschile Jan 18, 2023
6547122
update experimental description
mschile Jan 18, 2023
41c8827
await endprofiling
mschile Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
getting more metrics
  • Loading branch information
mschile committed Dec 17, 2022
commit 823648a75abe7d3b7b1cdec1da8c17597ff5bb2c
4 changes: 3 additions & 1 deletion packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
@@ -568,8 +568,10 @@ export class EventManager {
this.localBus.emit('script:error', err)
})

Cypress.on('test:before:run:async', (_attr, test) => {
Cypress.on('test:before:run:async', async (_attr, test) => {
this.studioStore.interceptTest(test)

await Cypress.automation('force:garbage:collection', {})
})

Cypress.on('test:after:run', (test) => {
5 changes: 0 additions & 5 deletions packages/driver/src/cypress.ts
Original file line number Diff line number Diff line change
@@ -544,11 +544,6 @@ class $Cypress {
case 'runner:test:after:run':
this.runner.cleanupQueue(this.config('numTestsKeptInMemory'))

// run garbage collection every 5th test in Chromium-based browsers
if (Cypress.isBrowser({ family: 'chromium' }) && args[0].order % 5 === 0) {
Cypress.automation('remote:debugger:protocol', { command: 'HeapProfiler.collectGarbage' })
}

// this event is how the reporter knows how to display
// stats and runnable properties such as errors
this.emit('test:after:run', ...args)
2 changes: 2 additions & 0 deletions packages/driver/src/cypress/source_map_utils.ts
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ const destroySourceMapConsumers = () => {
Object.values(sourceMapConsumers).forEach((consumer) => {
consumer.destroy()
})

sourceMapConsumers = {}
}

export default {
33 changes: 33 additions & 0 deletions packages/server/lib/browsers/cdp_automation.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export type CdpCommand = keyof ProtocolMapping.Commands
export type CdpEvent = keyof ProtocolMapping.Events

const debugVerbose = debugModule('cypress-verbose:server:browsers:cdp_automation')
const debugVerboseMemory = debugModule('cypress-verbose:server:browsers:cdp_automation:memory')

export function screencastOpts (everyNthFrame = Number(process.env.CYPRESS_EVERY_NTH_FRAME || 5)): Protocol.Page.StartScreencastRequest {
return {
@@ -176,6 +177,8 @@ export class CdpAutomation {
maxPostDataSize: 0,
})

await sendDebuggerCommandFn('Performance.enable')

return cdpAutomation
}

@@ -261,6 +264,34 @@ export class CdpAutomation {
})
}

private collectGarbage = async () => {
const performanceMemory = (await this.sendDebuggerCommandFn('Runtime.evaluate', { expression: 'memory = { usedJSHeapSize: performance.memory.usedJSHeapSize, totalJSHeapSize: performance.memory.totalJSHeapSize, jsHeapSizeLimit: performance.memory.jsHeapSizeLimit }', returnByValue: true })).result.value

debugVerboseMemory('performance.memory usage before: %o', performanceMemory)

const metrics = await this.sendDebuggerCommandFn('Performance.getMetrics')

debugVerboseMemory('Performance.getMetrics usage before: %o', { JSHeapUsedSize: metrics.metrics.find((m) => m.name === 'JSHeapUsedSize')?.value, JSHeapTotalSize: metrics.metrics.find((m) => m.name === 'JSHeapTotalSize')?.value })

const heapMetrics = await this.sendDebuggerCommandFn('Runtime.getHeapUsage')

debugVerboseMemory('Runtime.getHeapUsage usage before: %o', { JSHeapUsedSize: heapMetrics.usedSize, JSHeapTotalSize: heapMetrics.totalSize })

// only collect garbage if we're using more than 50% of the heap
// const shouldCollectGarbage = (performanceMemory.usedJSHeapSize / performanceMemory.jsHeapSizeLimit) > 0.50

// if (shouldCollectGarbage) {
// debugVerboseMemory('forcing garbage collection')
// performance.mark('gc-start')
// await this.sendDebuggerCommandFn('HeapProfiler.collectGarbage')
// performance.mark('gc-end')

// debugVerboseMemory('garbage collection measurement %o', performance.measure('garbage collection', 'gc-start', 'gc-end'))
// } else {
// debugVerboseMemory('skipping garbage collection')
// }
}

onRequest = (message, data) => {
let setCookie

@@ -351,6 +382,8 @@ export class CdpAutomation {
return this.sendCloseCommandFn(data.shouldKeepTabOpen)
case 'focus:browser:window':
return this.sendDebuggerCommandFn('Page.bringToFront')
case 'force:garbage:collection':
return this.collectGarbage()
default:
throw new Error(`No automation handler registered for: '${message}'`)
}
2 changes: 2 additions & 0 deletions packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
@@ -119,6 +119,8 @@ const DEFAULT_ARGS = [
// write shared memory files into '/tmp' instead of '/dev/shm'
// https://github.com/cypress-io/cypress/issues/5336
'--disable-dev-shm-usage',

'--enable-precise-memory-info',
]

let browserCriClient: BrowserCriClient | undefined