gpt4 book ai didi

java - TrueZip 压缩花费太多时间

转载 作者:行者123 更新时间:2023-12-01 11:39:46 27 4
gpt4 key购买 nike

我使用 TrueZip 进行压缩。这是我的代码的样子

  public String compress() throws IOException {
if (logLocations.isEmpty()) {
throw new IllegalStateException("no logs provided to compress");
}

removeDestinationIfExists(desiredArchive);

final TFile destinationArchive = new TFile(desiredArchive + "/diagnostics");
for (final String logLocation : logLocations) {
final TFile log = new TFile(logLocation);
if (!log.exists()) {
LOGGER.debug("{} does not exist, ignoring.");
continue;
}
if (log.isDirectory()) {
log.cp_r(destinationArchive);
} else {
final String newLogLocation =
new TFile(destinationArchive.getAbsolutePath()) + SLASH +
getLogNameFromPath(logLocation);
log.cp(new TFile(newLogLocation));
}
}
return destinationArchive.getEnclArchive().getAbsolutePath();
}

和我的测试

@Test
public void testBenchMarkWithHprof() throws IOException {
final FileWriter logLocations;
String logLocationPath = "/Users/harit/Downloads/tmp/logLocations.txt";
{
logLocations = new FileWriter(logLocationPath);
logLocations.write("Test3");
logLocations.write("\n");
logLocations.close();
}
final LPLogCompressor compressor = new LPLogCompressor("/Users/harit/Downloads/tmp",
new File(logLocationPath),
"/Users/harit/Downloads/tmp/TestOut");
final long startTime = System.currentTimeMillis();
compressor.compress();
System.out.println("Time taken (msec): " + (System.currentTimeMillis() - startTime));
}

我的数据目录Test3看起来像

Test3/
java_pid1748.hprof

文件大小为2.83GB当我运行测试时,花了22 分钟
但是,当我使用 native OSX 压缩(右键单击 -> 压缩) 压缩同一文件时,只需要2 分钟

为什么差别这么大?

谢谢

更新

根据@Satnam 的建议,我附加了一个调试器来查看发生了什么,这就是我发现的

enter image description here enter image description here

没有任何 TrueZip 线程正在运行?真的吗?抱歉,我是第一次使用探查器

最佳答案

本例中的原因是使用默认 Deflater这是 Deflater.BEST_COMPRESSION

我重写了 ZipDriver 类以超过级别

import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.socket.IOPoolProvider;

import java.util.zip.Deflater;

public class OverrideZipDriver extends ZipDriver {

public OverrideZipDriver(final IOPoolProvider ioPoolProvider) {
super(ioPoolProvider);
}

@Override
public int getLevel() {
return Deflater.DEFAULT_COMPRESSION;
}
}

然后在我的 Compressor 类中,我做了

public LPLogCompressor(final String logProcessorInstallPath, final File logLocationsSource,
final String desiredArchive) throws IOException {
this.desiredArchive = desiredArchive + DOT + getDateTimeStampFormat() + ZIP;
logLocations = getLogLocations(logProcessorInstallPath, logLocationsSource);
enableLogCompression();
}

private static void enableLogCompression() {
TConfig.get().setArchiveDetector(
new TArchiveDetector(TArchiveDetector.NULL, new Object[][]{
{"zip", new OverrideZipDriver(IOPoolLocator.SINGLETON)},}));
TConfig.push();
}

您可以阅读主题 here

关于java - TrueZip 压缩花费太多时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29633023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com