srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.09k stars 313 forks source link

Linux vs Windows performance differences #555

Closed Osiris-Team closed 4 months ago

Osiris-Team commented 4 months ago

The same backup zip creator code runs in 11 minutes on Windows and about an hour on Linux. Is there anyone that already experienced this, knows the cause, or maybe has any information about this? Is there something within zip4j that is the cause and can be fixed, or something within the following code?

Here is the relvant code:

            setStatus("Creating backup zip...");
            ZipFile zip = new ZipFile(server_backup_dest);
            ProgressMonitor progress = zip.getProgressMonitor();
            BThread _this = this;
            new Thread(() -> {
                try {
                    while (!_this.isFinished()) { // Parent thread
                        setStatus("Backing up " + progress.getFileName() + " " + progress.getPercentDone() + "% - " + progress.getCurrentTask());
                        Thread.sleep(100);
                    }
                } catch (Exception e) {
                    addWarning(new BWarning(this, e));
                }
            }).start();
            List<File> filesToBackup = new ArrayList<>();

            if (config.backup_include.asBoolean()) filesToBackup.addAll(config.getIncludedFiles());
            if (config.backup_exclude.asBoolean()) {
                List<File> excludedFiles = config.getExcludedFiles();
                for (File file :
                        excludedFiles) {
                    AL.debug(this.getClass(), "Excluded '" + file.getName() + "' from backup. Full path: " + file.getAbsolutePath());
                }
                ExcludeFileFilter excludeFileFilter = excludedFiles::contains;
                setMax(filesToBackup.size());
                for (File file : filesToBackup) { //Add each file to the zip
                    try {
                        ZipParameters zipParameters = new ZipParameters();
                        zipParameters.setExcludeFileFilter(excludeFileFilter);
                        if (file.isDirectory())
                            zip.addFolder(file, zipParameters);
                        else
                            zip.addFile(file, zipParameters);
                    } catch (Exception e) {
                        getWarnings().add(new BWarning(this, e, "Failed to add " + file.getName() + " to zip."));
                    }
                    step();
                }
            } else {
                setMax(filesToBackup.size());
                for (File file : filesToBackup) { //Add each file to the zip
                    try {
                        if (file.isDirectory())
                            zip.addFolder(file);
                        else
                            zip.addFile(file);
                    } catch (Exception e) {
                        getWarnings().add(new BWarning(this, e, "Failed to add " + file.getName() + " to zip."));
                    }
                    step();
                }
            }

Full: https://github.com/Osiris-Team/AutoPlug-Client/blob/20a2a4700646d173ad8ca1095948096c04d9ba4d/src/main/java/com/osiris/autoplug/client/tasks/backup/TaskBackup.java#L106

srikanth-lingala commented 4 months ago

I haven't heard of such an issue so far. My guess is that the linux device is slow or is dedicating limited resources to this process. It might be that the read/write of the file is slow on linux machine compared to the Windows machine. I would recommend you to do a profiling of your application to investigate further

Osiris-Team commented 4 months ago

Okay, thanks!