18

How do I enable multi-threaded LZMA2 using 7-zip 9.20 on the command line? I know this is normally done with the -t option like so: "-tzip" .

How do I do this with LZMA2? I tried -tlzma and -tlzma2 and neither one works. I also tried not passing -t at all, and it just runs single threaded with "lzma" mode.

Here is the command I currently have, but it is slow, and single threaded:

"C:\Program Files\7-Zip\7z.exe" a -r -tzip -y XMLBackup.zip *.xml
1
  • 7zip version 23 multithreads making 7z files by default.
    – js2010
    Dec 5, 2023 at 18:15

5 Answers 5

11

Try -m0=lzma2

"C:\Program Files\7-Zip\7z.exe" a -m0=lzma2 -r -y XMLBackup.zip *.xml

more info

2
  • 8
    This combined with -mmt=x did the trick for me. It seems that if lzma2 is not specified that it uses the older lzma compression and therefore can't use multiple threads. If you specify both options, it will be able to use multithreading.
    – Kibbee
    Oct 25, 2012 at 15:24
  • I get "error, not implemented" for a zip file. It seems to work for -m0=bzip2 though. -m0=lzma seems to use two threads. Why -m0 instead of -m, which the chm help file says, but doesn't work?
    – js2010
    Sep 30, 2023 at 15:37
5

The help file says it's mt=number_of_threads

I know this is specifically about the command line, but one thing I can say about when using the GUI, as soon as you switch to LMZA2 you got all the options. And it DOES speed up compression a great deal, utilizing the full 100% of your CPU's power rather than the usual 25%.

5
7z a -txz -mx=9 -mmt=on out.tar.xz in.tar

-txz uses XZ (LZMA2)

-mx=9 sets the compression level (1 fastest / 9 best compression)

-mmt=on LZMA2 only supports up to 2 threads (either -mmt=on or -mmt=off) but multithreading is on by default

https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm#XZ

1
  • 3
    Somehow that statement about up to two threads doesn't really seem to concern 7z or it's outdated information. At least in my case 7z was topping as many CPU cores as I told it to use threads when the machine was otherwise idle. Aug 21, 2020 at 12:50
1

The multithreading mode is given in a -m flag, and it's apparently only implemented for zip, 7z, bzip2 and xz. More specifically, -mmt=<<# of threads>>. However, according to the documentation, it is enabled by default. See the CHM manual included with 7-zip for more information.

3
  • I tried it and didn't notice any apparent speed increase. I am not entirely convinced it works.
    – djangofan
    Apr 4, 2012 at 20:30
  • How many physical cores is windows seeing in your computer? You can tell whether multithreading is being used by CPU usage; it's possible that you're already seeing the best speed and turning multithreading off just makes it even slower.
    – Jessidhia
    Apr 4, 2012 at 23:12
  • I already thought of that. I opened 7-zip (version 9.20) and I looked at what it "detected" as the number of cores. That is the number I used.
    – djangofan
    Apr 6, 2012 at 2:25
0

As of 2023: The default command seems to take advantage of all my cores (32 core AMD CPU) and uses max compression.

When my folder has only one file inside, the cpu usage is low. If there are many large files, the cpu usage grows beyond 50%. Which I think explains why some people think it is not working?

I use the following PowerShell script to compress all sub-dirs into their own 7z archives. EG: It takes a dir with sub-folders: A, B, C and outputs: A.7z, B.7z, C.7z You can see the actual 7zip command on the last line, I have no flags set other than: -bsp1 for verbose logging and this ends up using all my cores when needed.

$rootDir = Get-Location # Can select the parent dir here
$7zipPath = "7z.exe" # Replace with the path to 7zip if not in PATH

Get-ChildItem -Path $rootDir -Directory | ForEach-Object {
    $folderName = $_.Name
    $outputFile = Join-Path $rootDir "$folderName.7z"
    & $7zipPath a -bsp1 $outputFile $_.FullName
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .