I needed to run convert
with a lot of images at the same time. The command took quite a while but this doesn't bother me.
The issue is that this command rendered my computer unusable while the command was running (for about 15 minutes).
So is it possible to throttle the command by limiting resources (processor and memory) to the command, directly from the command line? This can only work if I add something to the same line before pressing Enter because once I start the process the computer slows so much that it is impossible for example to switch to "System monitor" and reduce priority.
Edit: top and iotop results
I managed to run top
and sudo iotop >iotop.txt
while doing one of these convert operations. (The iotop.txt file produced is difficult to read)
Results of top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 14275 username 20 0 4043m 3.0g 1448 D 7.0 80.4 0:16.45 convert
Results of iotop:
[?1049h[1;24r(B[m[4l[?7h[?1h=[39;49m[?25l[39;49m(B[m[H[2JTotal DISK READ: 1269.04 K/s | Total DISK WRITE:[59G0.00 B/s (B[0;7m TID PRIO USER DISK READ DISK WRITE SWAPIN(B[0;1;7m IO>(B[0;7m COMMAND [3;2H(B[m2516 be/4 username 350.08 K/s 0.00 B/s 0.00 % 0.00 % zeitgeist-datahub 7394 be/4 username 568.88 K/s 0.00 B/s 77.41 % 0.00 % --rendere~.530483991[5;1H14275 idle username 350.08 K/s 0.00 B/s 37.49 % 0.00 % convert S~f test.pdf[6;2H2048 be/4 root[6;24H0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/3:2] [5G1 be/4 root[7;24H0.00 B/s 0.00 B/s 0.00 % 0.00 % init
Furthermore, even after the process ends, the computer does not return to the previous performance. I found a way around this by running sudo swapoff -a
followed by sudo swapon -a
man nice
, and if you need I/O throttlingman ionice
.Let's look at some simple examples.
Throttling CPU usage:
From your description, however, CPU usage is almost certainly not your real problem here. More likely, you're having severe I/O contention.
Throttling Disk Usage:
-c2
is "best effort", and-n7
is the lowest "best effort" priority. So, this will throttle the job to lower I/O priority than most other things on the system.-c3
(no priority level necessary) means "Idle only". Jobs set to-c3
ONLY take up otherwise idle disk scheduling time, for virtually no impact at all on the system - but potentially a considerably longer execution time for your job, depending on how busy the rest of the system gets.Oh, boy, I just caught this... quoting OP:
OK, so that means you were exhausting the available RAM on your system, which means you're just plain trying to run too many
convert
processes at once. We'd need to look at your actual syntax in spawningconvert
to advise, but basically, you need to make sure you don't try to open more simultaneous processes than you have the RAM to comfortably handle.Since you state what's causing this is
convert *.tif blah.pdf
, what's happening is that the content of every single TIF and its conversion to PDF are getting stuffed into RAM at once. What you need to do is split the job up so that this isn't necessary. One possibility that leaps to mind is instead doing something likefind . -iname '*.tif' | xargs -I% convert % %.pdf
, then usingpdftk
or something like it to glue all the individual pdfs together. If you really want to get fancy, and you have a multicore CPU, this also affords you the chance to write a small script to run conversions in batches of n, where n is your number of cores, and get the whole thing done significantly faster. :)pdftk how-to: http://ubuntuhowtos.com/howtos/merge_pdf_files (basically boils down to
sudo apt-get install pdftk; pdftk *.pdf cat output merged.pdf
)Here's a pretty good article on using a program called
cpulimit
to limit the cpu usage of any process:http://maketecheasier.com/limit-cpu-usage-of-any-process-in-linux/2010/09/22
The problem is like you said finding the PID of the
convert
process after it has started.After starting
convert
if you can still type commands in the terminal you can runps aux | grep convert
to find it's PID, thensudo cpulimit -p PID -l CPU%
to start throttling.Or if starting
convert
also locks up your terminal the article shows you how you can runcpulimit
as a background daemon that will automatically monitor and throttle any processes over a certain amount of CPU usage. Good luck!