【问题标题】:TrueZip compression taking too much timeTrueZip 压缩耗时过长
【发布时间】:2015-04-15 05:08:50
【问题描述】:

我使用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 compress (right click -> compress) 压缩同一个文件时,只需要 2 分钟

为什么会有这么大的区别?

谢谢

更新

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

TrueZip 线程都没有运行?真的吗?抱歉,我是第一次使用分析器

【问题讨论】:

  • 为什么不使用分析器?
  • 有区别吗 - 文件属性,如所有者和只读存储? (可在一个小目录上测试)。使用标准 java 意味着可以制作一个 zip 文件系统,只需使用 Files.copy 进行一次复制操作即可将目录从磁盘复制到 zip 中。
  • @satnam,我更新了快照,你看到差异了吗?
  • @JoopEggen,完全一样的文件,我很困惑
  • 您应该使用采样器或分析器并拍摄快照。你显示的屏幕没用。也许先阅读一下如何使用分析器并自己分析结果,然后再将它们发布在这里供我们为您分析。

标签: java compression truezip


【解决方案1】:

本例中的原因是使用默认的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

【讨论】:

猜你喜欢
  • 2021-12-28
  • 2013-06-16
  • 2013-02-26
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多