Replies: 4 comments
-
Do you see an increase in memory in chromium or dotnet? |
Beta Was this translation helpful? Give feedback.
-
@kblok Even after resetting page content with await page.SetContentAsync("") after each PDF generation, metrics like JSHeapUsedSize from page.MetricsAsync() keep increasing for each pooled page. |
Beta Was this translation helpful? Give feedback.
-
So it's more the browser having a memory leak. Maybe you could try closing the page and opening a new one after each generation? |
Beta Was this translation helpful? Give feedback.
-
I’ve been thinking about two possible optimizations:
I’ve noticed Playwright samples dispose pages after each use, but I’m not sure if this is the recommended best practice or if it could cause other issues. Would appreciate any further insights or references. Thanks again! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Title:
High Memory Usage with PuppeteerSharp Page Pooling – Is Page Reuse Recommended for PDF Generation?
Body:
I'm using PuppeteerSharp in a .NET backend service to generate PDFs at scale. To improve throughput, I implemented a pool of 10 IPage objects and reuse them for each PDF generation request.
Here’s a simplified version of my pooling logic:
Issue:
Over time, I observe that memory usage on the server keeps increasing and does not decrease, even after many PDF generations.
The following screenshot (Linux, top command) shows multiple Chromium processes and sustained high memory consumption
Questions:
Is pooling and reusing IPage objects a recommended practice in PuppeteerSharp for high-concurrency PDF generation?
Would it be more efficient and stable to create a new page for each request and dispose it immediately after use?
Are there any best practices or patterns for managing memory and resource cleanup in this scenario?
Any insights, recommendations, or real-world experiences would be greatly appreciated!
Thanks
Beta Was this translation helpful? Give feedback.
All reactions