I've built an API using Laravel with a centos installed server.
In the API, there is a process that uses headless chrome like this to get an HTML source.
[MyController.php]
$url = $request['url'];
$browser = $browserFactory->createBrowser(
[
'headless' => true,
'noSandbox' => true,
]
);
try{
$this->page = $browser->createPage();
$this->page->navigate($url)->waitForNavigation(Page::LOAD, 60);
$response = $this->page->evaluate('document.documentElement.outerHTML')->getReturnValue();
$resolvedURL = $this->page->getCurrentUrl();
// too long to load
} catch (OperationTimedOut $e) {
$response = null;
$resolvedURL = null;
// An other page was loaded
} catch (NavigationExpired $e) {
$response = null;
$resolvedURL = null;
} finally {
$browser->close();
}
// analyze retrived html code
.
.
.
Now, my server has a high load average problem due to high CPU Usage and I tried to figure out the reasons why.
I have many HTTP requests to this API obviously as you can see many PHP-fpm processes are running on the screenshot.
I'd like to lower the load average on the server without regulating the number of PHP-fpm max children, but I'm not really good at server managing.
To lower the CPU Usage, what I can do? I did my best to optimize my PHP code already.
Like is it possible to share one Chrome process in all PHP-fpm processes so that I don't have to create a chrome process for each HTTP request?