Как установить LZ4_NBWORKERS?Python

Программы на Python
Ответить
Anonymous
 Как установить LZ4_NBWORKERS?

Сообщение Anonymous »

Я использую LZ4 v1.10.0 — многоядерную версию. Я хотел бы настроить LZ4_NBWORKERS для использования преимуществ многоядерных процессоров:

Код: Выделить всё

import subprocess, time, platform, sys, os

# Information of the system
print('OS:', platform.platform())
print('CPU:', platform.processor())
print('Number of logical cores:', os.cpu_count())
print('Python:', platform.architecture()[0], platform.machine(), sys.version)

# Paths
tarPath         = "tar"  # Windows 11 has tar.exe on PATH
lz4Path         = r"C:\Users\Akira\Downloads\Compressed\lz4_win64_v1_10_0\lz4.exe"
srcDir          = r"E:\Personal Projects\tmp"
filesToArchive  = ["chunk_0.ndjson", "chunk_0.ndjson"]
outLz4          = r"E:\Personal Projects\tmp\test.tar.lz4"

# Version of lz4
print()
result  = subprocess.run([lz4Path, "-V"], capture_output=True, text=True, check=True)
print("STDOUT:", result.stdout.strip())
print()

# Prepare the command
# Using CMD syntax to set env variable + pipe
for nCore in range(1, 10):
cmd     = f'set LZ4_NBWORKERS={nCore} && tar -C "{srcDir}" -cf - {" ".join(filesToArchive)} | "{lz4Path}" -f - "{outLz4}"'
start   = time.perf_counter()
result  = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
end     = time.perf_counter()
print("The running time with", nCore, "threads is", round(end-start), "seconds.")
#    print("STDERR:", result.stderr.decode())
Похоже, что улучшения скорости нет:

Код: Выделить всё

OS: Windows-11-10.0.26200-SP0
CPU: AMD64 Family 25 Model 68 Stepping 1, AuthenticAMD
Number of logical cores: 16
Python: 64bit AMD64 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:37:03) [MSC v.1929 64 bit (AMD64)]

STDOUT: *** lz4 v1.10.0 64-bit multithread, by Yann Collet ***

The running time with 1 threads is 11 seconds.
The running time with 2 threads is 12 seconds.
The running time with 3 threads is 13 seconds.
The running time with 4 threads is 14 seconds.
The running time with 5 threads is 14 seconds.
The running time with 6 threads is 13 seconds.
The running time with 7 threads is 13 seconds.
The running time with 8 threads is 9 seconds.
The running time with 9 threads is 13 seconds.
Как правильно настроить LZ4_NBWORKERS?
Спасибо за объяснение и счастливого нового года.>

Подробнее здесь: https://stackoverflow.com/questions/798 ... -nbworkers
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»