[solved] Limit 7z CPU Usage

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Nikolai5
Level 4
Level 4
Posts: 309
Joined: Thu Dec 23, 2021 5:25 pm
Location: Northern England

[solved] Limit 7z CPU Usage

Post by Nikolai5 »

Hi,

When archiving and encrypting very large files with 7z it uses the majority of my CPU which is 16 threads. Is there a way to limit it to say 10 for example?

I have seen there is a switch named "-stm" but I'm not sure if that does it or what input it is looking for other than a hexadecimal value of some kind.

I don't want to change the "priority" of the process, I just want to limit the threads it is able to use. Similar to how make -j if possible.
Last edited by LockBot on Fri Feb 10, 2023 11:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
t42
Level 11
Level 11
Posts: 3683
Joined: Mon Jan 20, 2014 6:48 pm

Re: Limit 7z CPU Usage

Post by t42 »

if you are using 7z provided by p7zip package, using -mmt1 approximately halves the CPU resource usage, -mmt2 will make it about 3/4 on 4x CPU.

edit

as for -stm for half of the 16 threads try F0F0 or AAAA, don't have such CPU to check it here.
For 4x CPU -stmA switch is using 2 threads for sure. Important - it works only for 7zip package, not p7zip-full.
You need to install 7zip separately and invoke it with 7zz command.
-=t42=-
Nikolai5
Level 4
Level 4
Posts: 309
Joined: Thu Dec 23, 2021 5:25 pm
Location: Northern England

Re: Limit 7z CPU Usage

Post by Nikolai5 »

t42 wrote: Wed Aug 10, 2022 5:03 pm if you are using 7z provided by p7zip package, using -mmt1 approximately halves the CPU resource usage, -mmt2 will make it about 3/4 on 4x CPU.
-mmt works great. Exactly what I was looking for, thanks for the tip. I am using the p7zip package. I read the man pages for 7z and p7zip but neither of them mention anything other than -stm which is why I mentioned that, but -mmt works.

Thanks.
t42
Level 11
Level 11
Posts: 3683
Joined: Mon Jan 20, 2014 6:48 pm

Re: [solved] Limit 7z CPU Usage

Post by t42 »

You're welcome. In case of compression of compressed files such as jpeg, mkv, flac, I prefer to use a low compression switch just to significantly reduce operation time. Here is a comparison for directory containing flac files. Note that no compression size for -mx=0 and -mx=1 is less -mx=3

7z a -r -t7z -m0=lzma2 -mx=0 ... 7z a -r -t7z -m0=lzma2 -mx=9

Code: Select all

Bites       Switch   Sec
220 948 859  orig.
220 491 866 -mx=0    07
220 508 908 -mx=1    09
220 529 718 -mx=3    14
214 545 781 -mx=5    15
205 809 680 -mx=7    62
205 809 680 -mx=9   102
-=t42=-
Nikolai5
Level 4
Level 4
Posts: 309
Joined: Thu Dec 23, 2021 5:25 pm
Location: Northern England

Re: [solved] Limit 7z CPU Usage

Post by Nikolai5 »

t42 wrote: Thu Aug 11, 2022 2:24 am You're welcome. In case of compression of compressed files such as jpeg, mkv, flac, I prefer to use a low compression switch just to significantly reduce operation time. Here is a comparison for directory containing flac files. Note that no compression size for -mx=0 and -mx=1 is less -mx=3

7z a -r -t7z -m0=lzma2 -mx=0 ... 7z a -r -t7z -m0=lzma2 -mx=9

Code: Select all

Bites       Switch   Sec
220 948 859  orig.
220 491 866 -mx=0    07
220 508 908 -mx=1    09
220 529 718 -mx=3    14
214 545 781 -mx=5    15
205 809 680 -mx=7    62
205 809 680 -mx=9   102
Ah, thanks. This is useful because I actually don't care so much about the compression, as where I'm putting this file only needs one copy of these, and it has plenty of space. And as your example results show, the file size difference at the end isn't really drastic enough to warrant the time spent.

Cheers.
Locked

Return to “Scripts & Bash”