Reputation: 13986
I'm using puppeteer via the Node API on a Linux host. My use case is to create different sized screenshots of a WebGL map.
The node script is called via command line arguments, it generates a few screenshots in different sizes and then exits.
My problem is that puppeteer process slows down the webserver a lot, as they are on the same host.
How can I make sure that puppeteer processes and Chrome child processes start in lowest/idle process priority?
Here is the skeleton of my Node script:
const puppeteer = require('puppeteer')
const SCREENSHOT_SIZES = ...
async function run() {
const browser = await puppeteer.launch({})
for (const size of SCREENSHOT_SIZES) {
const page = await browser.newPage()
await page.setViewport({
width: size.w,
height: size.h,
})
try {
await page.goto(url, { waitUntil: 'networkidle0', timeout: 60 * 1000 })
} catch (error) {
console.error(error)
}
await page.screenshot({
path: ...
})
}
await browser.close()
}
run()
Upvotes: 1
Views: 1160
Reputation: 29037
You can use browser.process().pid
to obtain the pid
of the spawned browser process. Then you can use os.setPriority()
to set the scheduling priority for the process specified by the browser's pid
.
Complete Example:
'use strict';
const os = require( 'os' );
const puppeteer = require( 'puppeteer' );
( async () =>
{
const browser = await puppeteer.launch();
os.setPriority( browser.process().pid, 15 );
const page = await browser.newPage();
await page.goto( 'https://www.example.com/' );
await browser.close();
})();
Upvotes: 2