instagram

MarcEdit: Networked Task Folders and network latency

I had a really interesting question make it into my email the other day.  A user had configured MarcEdit to use a networked task folder, and in general, it was working.  But then, it wouldn’t.  The folder was there, the tasks were there, but the program simply wouldn’t see the network.  Maybe that has happened to you – you’ve selected a network task folder, uploaded the changes, and then had MarcEdit fall back into offline mode.  So what’s happening?

Well, the culprit here is network latency most likely.  Here’s the problem – Windows, by default, will keep trying and trying and trying to connect to a networked folder.  By default, the timeout to reconnect to a networked device is over 100 seconds.  When you are offline, that would make performance simply unacceptable, because the areas where networked task directories need to be resolved would simply freeze, locking the program. To solve that issue, I have a small function in the application that checks to see if a directory exists (the Networked Task directory), and it sets a timeout.  By default, I’ve set the timeout to be 300 milliseconds.  This doesn’t sound like a very long time, but it’s ages in network time.  All the network has to do is respond to a ping.  To support this, I use a function that looks something like this:

private bool VerifyDirectoryExists(Uri uri, int timeout)
{
     var task = new System.Threading.Tasks.Task(() =>
     {
         var fi = new System.IO.DirectoryInfo(uri.LocalPath);
         return fi.Exists;
     });
     task.Start();
     return task.Wait(timeout) && task.Result;
}

If you look at the code, you’ll see I have a timeout that can end a specific thread and thus, allow the program to continue.  This is how MarcEdit determines if the network folder is offline.  It works well, but if there is significant latency on the network, 300 milliseconds may be too small. 

To support users that may run into this problem, I’ve added a new preference.  In the Locations tab, I’ve added the ability to change the latency timeout. 

image

By default, this value will remain at 300 milliseconds, but uses have the option to change this value.  Users also need to keep in mind, that the timeout is set in milliseconds, and there is a maximum value of 100 seconds (the windows default timeout, which is controlled via the registry).  Personally, I would recommend against setting this value above 1 second or (1000 milliseconds), because you will notice program freezing when truly offline.  What’s more, I’d argue that if your networks latency requires this kind of setting, using the networking options likely isn’t the best choice given your environment.  But these options are now available for users.  This feature has was rolled into the Windows version as of Update build 6.2452 and will be moved into the MacOS version of MarcEdit later this week.

–tr

0 Comments

Leave Your Reply

Your email address will not be published. Required fields are marked *

*

*