Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing CPU processing time by using nice?

Tags:

linux

bash

backup

My hosting provider (pairNetworks) has certain rules for scripts run on the server. I'm trying to compress a file for backup purposes, and would ideally like to use bzip2 to take advantage of its AWESOME compression rate. However, when trying to compress this 90 MB file, the process sometimes runs upwards of 1.5 minutes. One of the resource rules is that a script may only execute for 30 CPU seconds.

If I use the nice command to 'nicefy' the process, does that break up the amount of total CPU processing time? Is there a different command I could use in place of nice? Or will I have to use a different compression utility that doesn't take as long?

Thanks!


EDIT: This is what their support page says:

  • Run any process that requires more than 16MB of memory space.
  • Run any program that requires more than 30 CPU seconds to complete.

EDIT: I run this in a bash script from the command line

like image 732
Matt Avatar asked Feb 03 '26 23:02

Matt


2 Answers

nice will change the process' priority, and thus will get its CPU seconds sooner (or later), so if the rule is really about CPU seconds as you state in your question, nice will not serve you at all, it'll just be killed at a different time.

As for a solution, you may try splitting the file in three 30 MB pieces (see split(1)) which you can compress in the allotted time. Then you uncompress and use cat to put the pieces together. Depending on if it's a binary or text you can use the -l or -b arguments to split.

like image 78
Vinko Vrsalovic Avatar answered Feb 05 '26 14:02

Vinko Vrsalovic


nice won't help you - the amount of CPU seconds will still be the same, no matter how many actual seconds it takes.

like image 44
bzlm Avatar answered Feb 05 '26 14:02

bzlm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!