Apache / PHP code compilation represents the majority of the time it takes to complete a build in an EasyApache run on a server. Unfortunately even with the increase in the number of cores per server the time it takes to complete a build still hasn’t improved much. The reason being cPanel doesn’t take advantage of the extra CPU cores that you may have on your server. The cPanel folks are very nice and very helpful but as an ISV they must prioritize feature requests (understandably). So one would need to submit a feature request to cPanel for upvoting.
But I didn’t write all of this to leave it at that. There’s a fix! Albeit not so much of a clean fix but at least you’ll spend less time staring at the build screen during those late Saturday night maintenance windows. So let’s get into the meat of the post. Make, the tool that spawns gcc/cc instances to compile code, gives us the option to specify the number of cc tasks it can spawn at once in parallel to compile code. By default, a maximum of two tasks are spawned in a cPanel build. It means your server will compile at most two files at once out of thousands of source code files between PHP, Apache, and other modules. This inefficiency leads to the The option that we feed to the make tool is the flag -j follow by a number like make -j2. If you have a server with 8 cores, a flag of 0f -j10 will speed up the build dramatically.
But why 10 and not 8? The hypothetical server has 8 cores not 10. The answer is we want to make sure all 8 cores are kept busy at all times including when a core is waiting on an IO job to complete. So why not give the CPU some non-IO bound task to do while the other one is pending? Alright here are the steps you need to follow to take advantage of the multi core compiling goodness:
1) Open file /var/cpanel/perl/easy/Cpanel/Easy/Utils.pm with your favorite editor (vi, pico, or nano, etc)
2) Search for the string: j2. It should be close to line 1711
3) Replace j2 with jX where X is a number representing the number of cores your server has plus 2. Ex: for an 8 core server, X is 10 or j10
4) Save and close the file then run: chattr +i /var/cpanel/perl/easy/Cpanel/Easy/Utils.pm
5) Rebuild Apache/PHP (usually using /scripts/easyapache –build &> /tmp/build.out &)
6) Watch the build complete in record time! Tail /tmp/build.log to follow progress
7) Once the build completes, restore the immutable attribute to its original setting: chattr -i /var/cpanel/perl/easy/Cpanel/Easy/Utils.pm
8) You’re done
That’s all folks. We hope you enjoyed this one!