Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I run a convert *.tif bla.pdf command sometimes with say 60 images. Now this renders my computer unusable until it finishes.

I tried using nice and ionice but it did not help much.

Is there a way to limit resources (disk read/writes and maybe cpu) to the convert command?

share|improve this question
2  
ionice -c 3 (idle priority class) should have no impact on regular system activity. If you say it still renders your computer unusable, I'd suspect something is wrong (e.g. had disk problems, etc.) You need to trace and fix that problem first. Check your logs (especially the kernel log) for unusual errors, etc. –  haimg Nov 26 '12 at 15:57
    
Maybe it is because it uses a lot of CPU as well. I actually tried to "chain" ionice and nice ionice -c 3 nice -n 20 convert. Is it a bad idea? –  To Do Nov 26 '12 at 16:05
    
It's not a bad idea per se (nice and ionice are orthogonal), but I'd rather find out what's wrong before trying random tricks. Your computer should not behave like this in any case, it's not normal. –  haimg Nov 26 '12 at 16:41
    
I think that nice and ionice only modify priority to commands but do not prevent them to use all resources. The moment another app requires resources it needs to "wait" until the operation ends to get it's needs. What about using ulimit to keep a "reserve" i/O and cpu? –  To Do Nov 26 '12 at 16:48

2 Answers 2

up vote 1 down vote accepted

Actually the problem is that all the tiff files were being loaded into RAM at one time. The problem was not related to CPU usage nor to read/write operations to disk (well, sortof). It was filling RAM (4Gb) and then using Swap.

So, as suggested by someone I split the procedure in two steps.

  1. find . -iname '*.tif' | xargs -I% convert % %.pdf converts each image separately
  2. pdftk *.pdf cat output merged.pdf && rm *.tif.pdf merges the pdf files and deletes the individual pdf's.

Overall it was faster and the computer was not blocked.

share|improve this answer

Try installing and using "cpulimit". I think the detrimental effect that such processes (convert/imagemagick batches) have is more likely due to CPU load than I/O, at least that's my impression. I'm not sure about RAM; I actually I'm not sure that convert will load all into RAM at once. For example, even if you convert a PDF with imagemagick, it will first use gs and extract page by page, and then convert the PGN pages on /tmp to whatever specification and format you gave on imagimagick/convert (but in the other hand that's the "other way around", extracting images from PDF rather than generating the PDF, so I don't know).

I have the impression that cpulimit is more effective on longstanding processes or "endogenous" batch processes of a given process (like whatever imagemagick does), but that it doesn't work as well dealing with something that's repeatedly called in a bash loop, for example (unless perhaps it's on a script and cpulimit is issue to restrict the CPU usage of that script). To reduce the CPU load of repeatedly running processes I think the best way is to add some arbitrary delay (sleep) within the loop (it can be somehow adaptive, like modulating the sleep time by some number you get from something like "top" or perhaps preferably some other, less cpu-intensive itself (something on /proc/stat ?), indication of CPU usage).

share|improve this answer
    
The swap becomes heavily used and RAM almost full. –  To Do Jul 15 at 7:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.