Results 1 to 9 of 9

Thread: Slow FileSystemObject

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    362

    Slow FileSystemObject

    My VB6 project is connecting to the company server (database and files) via VPN.
    Many processes are using FileSystemObject to work with files. Some statements like Set objServerFile in the following procedure for instance
    Code:
    Dim objFSO As Object
    Dim objServerFile As Object
    Dim strSource As String
        'strSource = "the path and file name" '- the value is depending on some parameters. 
        'I just do not show it here, but it is always the same for the same company. 
        'Application is used by several companies and each company has its own value.
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
    
        Set objServerFile = objFSO.GetFile(strSource)
    work strange for me. In one case it takes a portion of the second, in some other cases it may take up to 25 seconds.
    I'm wondering what it depends on? Internet speed on the server side is 100Mbps, on my side it is 1Gbps.
    What should be checked by me (developer) and by technician team?

    Thank you

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Slow FileSystemObject

    What are you doing with the file? Why use FSO? In all the years I have been doing this I can't think of even once where I needed to use FSO in a VB6 application. In most cases it is the slowest option available and not needed. I have used it in scripting where I did not have other options but not in a real app.

    In yoru case though I would suspect network connection issues. I see some times even on my own LAN where some pcs can take a good while to make the initial connection to another pc on the LAN, once the connection is made they are very quick. So in your lag possibly related to establishing a connection to the network share? Have you tried adding a line above that one that tries to access that network location and see if it is also slow sometimes? Something like the Dir$() function for example.

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Slow FileSystemObject

    Also, the VPN is likely introducing some overhead that could contribute to slower transfers.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    362

    Re: Slow FileSystemObject

    This particular usage of FSO is to compare 2 files with the same name located on the server and the workstation and in case they are different to replace the file on the workstation with the file from server. Like this:
    Code:
    Public Sub UpdateHelp2()
    Dim objLocalFile As Object
    Dim objServerFile As Object
    Dim strSource As String
    Dim strDestination As String
    Dim objFSO As Object
    Dim strAppPath As String
    Dim datModifiedDateLocal As Date
    Dim datModifiedDateServer As Date
    
        'Check if local Help folder exists
        If blnDataLocation = False Then 'Don't it for local Coordinator
            If Dir(App.path & "\LocalData", vbDirectory) = "" Then
                MkDir (App.path & "\LocalData")
            End If
            If Dir(App.path & "\LocalData\Help", vbDirectory) = "" Then
                MkDir (App.path & "\LocalData\Help")
            End If
        End If
        strAppPath = App.path
        If Right(strAppPath, 1) = "\" Then
            ' Remove the trailing backslash
            strAppPath = Left(strAppPath, Len(strAppPath) - 1)
        End If
        strDestination = strAppPath & "\LocalData\Help\CoordinatorHelp.chm"
        
        If blnDataLocation = False Then
            strSource = strMappedDrive & "\" & strCoordinatorFolder & "\Data\Help\CoordinatorHelp.chm"
        Else
            strSource = strAppPath & "\Data\Help\CoordinatorHelp.chm"
        End If
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objServerFile = objFSO.GetFile(strSource)
        datModifiedDateServer = objServerFile.DateLastModified
        Set objLocalFile = objFSO.GetFile(strDestination)
        datModifiedDateLocal = objLocalFile.DateLastModified
        'Copy Help from the server
        If datModifiedDateLocal <> datModifiedDateServer Then
            If strSource <> "" Then
                objFSO.CopyFile strSource, strDestination, True
            End If
        End If
        Set objFSO = Nothing
    End Sub
    I do not know any other ways to do this.
    If creating initial connection requires some significant time then why it is not always takes a long time. I do not think that PC may keep open connection when the program stops and even workstation is rebooted.
    Can you suggest any method to establish connection faster?

    Thank you

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    362

    Re: Slow FileSystemObject

    This particular usage of FSO is to compare 2 files with the same name located on the server and the workstation and in case they are different to replace the file on the workstation with the file from server.
    This is help file with chm extention and it is not opening from the server. The file should be located on the workstation. So, the procedure is like this:
    Code:
    Public Sub UpdateHelp2()
    Dim objLocalFile As Object
    Dim objServerFile As Object
    Dim strSource As String
    Dim strDestination As String
    Dim objFSO As Object
    Dim strAppPath As String
    Dim datModifiedDateLocal As Date
    Dim datModifiedDateServer As Date
    
        'Check if local Help folder exists
        If blnDataLocation = False Then 'Don't it for local Coordinator
            If Dir(App.path & "\LocalData", vbDirectory) = "" Then
                MkDir (App.path & "\LocalData")
            End If
            If Dir(App.path & "\LocalData\Help", vbDirectory) = "" Then
                MkDir (App.path & "\LocalData\Help")
            End If
        End If
        strAppPath = App.path
        If Right(strAppPath, 1) = "\" Then
            ' Remove the trailing backslash
            strAppPath = Left(strAppPath, Len(strAppPath) - 1)
        End If
        strDestination = strAppPath & "\LocalData\Help\CoordinatorHelp.chm"
        
        If blnDataLocation = False Then
            strSource = strMappedDrive & "\" & strCoordinatorFolder & "\Data\Help\CoordinatorHelp.chm"
        Else
            strSource = strAppPath & "\Data\Help\CoordinatorHelp.chm"
        End If
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objServerFile = objFSO.GetFile(strSource)
        datModifiedDateServer = objServerFile.DateLastModified
        Set objLocalFile = objFSO.GetFile(strDestination)
        datModifiedDateLocal = objLocalFile.DateLastModified
        'Copy Help from the server
        If datModifiedDateLocal <> datModifiedDateServer Then
            If strSource <> "" Then
                objFSO.CopyFile strSource, strDestination, True
            End If
        End If
        Set objFSO = Nothing
    End Sub
    I do not know any other ways to do this.
    If creating initial connection requires some significant time then why it is not always takes a long time. I do not think that PC may keep open connection when the program stops and even workstation is rebooted.
    Can you suggest any method to establish connection faster?

    Thank you

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Slow FileSystemObject

    Well like I indicated before FSO is likely not the culprit here, while it is slower than the other methods available in in a case such as this where it is only processing one file the speed difference would not be noticeable to the user.

    I would as I mentioned earlier add a DIR$() in there before the FSO stuff and have the DIR$() check the files existence on the server, If you see the same type of slowdown on the Dir$() statement then you are dealing with a network connection issue. If on the other hand the Dir$() statement processes quickly and it slows when it hits the FSO then I would get rid of the FSO and replace with either native VB code or API calls. My gut tells me it is network related.

    The related native VB Functions Dir$(), FileDateTime(), FileLen() and FileCopy()
    Last edited by DataMiser; Mar 5th, 2019 at 09:40 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    362

    Re: Slow FileSystemObject

    Thank you, I will try.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Slow FileSystemObject

    Accesses across the Internet are simply going to be slow no matter what, not only due to link speeds but also latency. Throw a VPN into the mix and you add more performance impediments due to the overhead for encryption/decryption, two or more additional links, and the latency of the VPN server(s) in the path.

    Then you need to consider that an idle connection is going to have start-up delays. The file sharing protocol must be negotiated and that can take several round-trips. Then authentication must be performed, so more round-trips. The good news is that once this is done additional operations will be quicker after the first one kicks off the entire circus.

    Finally you have turned the ravenous wasteful hog of FSO.GetFile() loose on it, so several more round-trips. The FSO.GetFile() method grabs a whole bunch of things just in case you might want to use them. Under the hood it makes a number of requests of the target filesystem to obtain this laundry list of tidbits.


    Even so though, I don't think you are going to speed things up noticeably by replacing your use of the FSO with anything closer to the bare metal. You aren't doing anything very extensive aside from the copy operation, and the file itself isn't likely to be huge enough to warrant anything more optimized.

    The SMB/CIFS Session Idle Connection Timer on a Windows Server is 15 minutes by default. See CIFS and SMB Timeouts in Windows. If 15 minutes go by with no activity and nothing open to the server the connection gets closed. After that if you try your file-fiddle-faddle again you will once again see a long startup delay.

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Slow FileSystemObject

    Is the "slow" VPN-Connection using TCP? And the "fast" ones using UDP?
    Is the MTU-Value the same between client and server?

    I had the issue with the VPN of my company (which sadly only allows TCP).
    changing the MTU-Value to the set Value of the Server jumped my speed up by a factor of 4 (it's still slow as hell, but, well....)
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width