Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Slow zippig when lots of files

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20027 |

    Hi,

    We are developing a web application where users can download multiple files zipped into one. We are however experiencing problems with the XCEED zip component.

    The problem is that when we try to zip over 30 files about 50 MB the zipping process will get extremely slow, and eventually stops. The zipping works fine when total size of files is under ~50 MB. We have monitored memory and processor usage on the machine (not the fastest on the market) that does the zipping and noticed following;

    when trying to zip files that have total size over ~50 MB, the processor load goes up to 100% as it should, but after few seconds it starts decreasing gradually to ~10%. At this point the zipfile virtually stops growing and the size of it is usually < 14MB  

    Below is the function in VB.net which does the zipping. We are using Visual Studio 2008, Framework 3.5, Visual Basic.net and Xceed.zip version 3.7.8257.17090

    ‘The parameter the function takes is a hashtable of absolute filepaths to the files that should be zipped.

    Private Sub CreateZipOfSelectedFiles(ByVal CollectionOfNodes As Collections.Hashtable)
            Dim aGUID As String = System.Guid.NewGuid.ToString
            Dim UniqueZipFilename As String = “CompressedDownload” & aGUID & “.zip”
            Dim FilenameList As New List(Of String)
            Dim ZipFile As AbstractFile
            Dim Archive As ZipArchive
            Dim ItemFile As AbstractFile
            Dim GroupFolder As AbstractFolder
            Dim ZippedFilesFolder As String
            Dim WholeZipFileName As String
            Dim CollectionIterator As DictionaryEntry
            Dim FolderTree As String
            Dim fileinfo As System.IO.FileInfo
            Dim OldZipFilesInfo As System.IO.DirectoryInfo

            ZippedFilesFolder = “C:\temp\tempZippedFiles\”
            WholeZipFileName = ZippedFilesFolder & UniqueZipFilename
            fileinfo = New System.IO.FileInfo(WholeZipFileName)

        Try
            Xceed.FileSystem.Licenser.LicenseKey = “XXXXXXXXXXXXXXXXXXX”
            Xceed.Zip.Licenser.LicenseKey = “XXXXXXXXXXXXXXXXXX”

            ZipFile = New DiskFolder(ZippedFilesFolder).GetFile(UniqueZipFilename)

            Archive = New ZipArchive(ZipFile)
            Archive.DefaultCompressionLevel = Xceed.Compression.CompressionLevel.Normal

            For Each CollectionIterator In CollectionOfNodes

                GroupFolder = Archive.GetFolder(“.\”)            
                FolderTree = “”
                FilenameList.Clear()
                FilenameList.AddRange(CollectionIterator.Key.ToString.Split(“\”))

                ItemFile = New DiskFile(TargetDir & CollectionIterator.Key.ToString)

                For Each Item As String In FilenameList
                    If Not Item = “” Then
                        FolderTree = FolderTree & “\” & Item

                        If Item = FilenameList(FilenameList.Count – 1) Then ‘a file
                            ItemFile.CopyTo(GroupFolder, False)
                        Else ‘a folder
                            GroupFolder = Archive.GetFolder(FolderTree)
                            If GroupFolder Is Nothing Then
                                GroupFolder = Archive.CreateFolder(FolderTree)
                            End If
                        End If
                    End If
                Next

            Next
            Response.Clear()
            Response.AppendHeader(“Content-Type”, “application/octet-stream”)
            Response.AppendHeader(“Content-Disposition”, “attachment; filename=” &     “CompressedDownload.zip”)
            Response.AppendHeader(“Content-Length”, fileinfo.Length)
            Response.TransmitFile(WholeZipFileName)
            Response.End()

         Catch ex As Exception
               Response.Output.WriteLine(“An error ocurred during the zipping process. ”             & ex.Messag, ex)
         End Try

    End Sub

    Are we using the component properly?

    Is this a known issue? If not, any help would bee appreciated.

    -Lauri

    Imported from legacy forums. Posted by Lauri (had 1666 views)

    User (Old forums)
    Member
    Post count: 23064

    Not sure why the CPU usage decreases, but one problem is that you are not using the batch update functionality offered by the component.  Add a BeginUpdate and EndUpdate block to you code, so the archive is actually created only once.  Right now, with the code  you have, every time you add a file to the archive, the complete archive is rebuilt, so that the more files you add (and the bigger they are), the worse the performance becomes.

    e.g.:

           Archive.BeginUpdate()

           For Each CollectionIterator In CollectionOfNodes

                GroupFolder = …

           Next

           Archive.EndUpdate()

    This way, files are compressed and gathered as you call CopyTo(), but not actually added to the archive.  Files will be added to the archive only at the EndUpdate() call.

     

    Imported from legacy forums. Posted by André (had 460 views)

    User (Old forums)
    Member
    Post count: 23064

    This solved the problem. Thank you!

    Imported from legacy forums. Posted by Lauri (had 1711 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.