Сжатие TrueZip занимает слишком много времени

Я использую 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 не запущен? действительно? Извинения Я использую профилировщик в первый раз

1 ответ

Решение

Причиной в этом случае было использование дефлатера по умолчанию, который 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();
  }

Вы можете прочитать ветку здесь

Другие вопросы по тегам