Configuration vs ConfigurationItems performance

Hello,

Based on a few tests, it looks like the Configuration API is at twice as fast as the ConfigurationItems API (for example listing 150 cameras takes 4 seconds with the Configuration API but 7 with the ConfigurationItems API).

Is this only for listing items or is it an overall “by design” latency when using the ConfigurationItems API?

There should not be any difference.

Perhaps the code being used will load both cameras and some of its ‘children’.

Can you show how the ConfigurationItems classes are being used?

Sorry for the delay. Here is sample code:

private static IEnumerable<Item> FindAllRecorders()
{
    Item serverItem = Configuration.Instance.GetItem(EnvironmentManager.Instance.MasterSite);
 
    List<Item> serverItems = serverItem.GetChildren();
    foreach (Item item in serverItems)
    {
        if (item.FQID.Kind == Kind.Server && item.FQID.ServerId.ServerType == ServerId.CorporateRecordingServerType)
            yield return item;
    }
}
 
private static IEnumerable<Item> FindAllCameras(IEnumerable<Item> items, Guid recorderGuid)
{
    foreach (Item item in items)
    {
        if (item.FQID.Kind == Kind.Camera && item.FQID.ParentId == recorderGuid && item.FQID.FolderType == FolderType.No)
            yield return item;
        else if (item.FQID.FolderType != FolderType.No)
        {
            foreach (var camera in FindAllCameras(item.GetChildren(), recorderGuid))
                yield return camera;
        }
    }
}
 
private static IEnumerable<Item> ConfigurationApiCameras()
{
    foreach (var recorder in FindAllRecorders())
    {
        foreach (var camera in FindAllCameras(recorder.GetChildren(), recorder.FQID.ServerId.Id))
            yield return camera;
    }
}
 
private static IEnumerable<Camera> ConfigurationItemsApiCameras()
{
    var ms = new ManagementServer(EnvironmentManager.Instance.MasterSite);
    var hardwares = ms.RecordingServerFolder.RecordingServers.Where(rs => rs.Enabled).SelectMany(rs => rs.HardwareFolder.Hardwares);
    var cameras = hardwares.Where(hw => hw.Enabled).SelectMany(hw => hw.CameraFolder.Cameras);
    return cameras.Where(c => c.Enabled);
}
 
private void Benchmark()
{
    // Build a string to ensure x.Count() is resolved and not optimised out
    string s = "";
 
    var stopWatch = new System.Diagnostics.Stopwatch();
    stopWatch.Start();
    var x = ConfigurationItemsApiCameras().ToList();
    s += $"ConfigurationItemsApiCameras {x.Count()}";
    stopWatch.Stop();
    s += $" {stopWatch.Elapsed}";
 
    s += " | ";
 
    var stopWatch2 = new System.Diagnostics.Stopwatch();
    stopWatch2.Start();
    var y = ConfigurationApiCameras().ToList();
    s += $"ConfigurationApiCameras {y.Count()}";
    stopWatch2.Stop();
    s += $" {stopWatch2.Elapsed}";
 
    Console.WriteLine(s);
}

This outputs:

ConfigurationItemsApiCameras 181 00:00:05.3876312 | ConfigurationApiCameras 181 00:00:00.8250932

Thank you for sharing your code and test, Milestone Development will start investigation.

Your ConfigurationAPICameras are not using our configuration API, but instead the SDK configuration structure. This structure will in many cases be loaded upon login and thus most likely is already loaded before you run your time measurements. Thus this part of your test is more or less entirely read from memory.

So the comparison is not really ‘fair’ as one is making a lot of requests towards the server during the measurements, whereas the other has done it before measurements are started.

Thanks.

Can you clarify what you mean that this example is not using the configuration API? Can you show an example of using the configuration API?

Does this mean that there are 3 (!) ways of accessing the cameras? One with the ConfigurationItems API, one with the Configuration API (that I don’t know of), and one with the “Configuration SDK Structure API” with Item and GetChildren()?

Kind regards,

Philippe

What we refer to as the Configuration API is a SOAP interface on our servers. You can read more about it here:

https://doc.developer.milestonesys.com/html/index.html?base=gettingstarted/intro_configurationapi.html&tree=tree_4.html

ConfigurationItems is not an API as such, but a namespace containing a large number of classes. It is basically a direct pass-through class interface on top of the Configuration API and thus we were a bit puzzled that you claimed to see significant differences between this and the Configuration API. You can see the classes in the namespace here:

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/namespace_video_o_s_1_1_platform_1_1_configuration_items.html&tree=tree_search.html?search=configurationitems

Finally the VideoOS.Platform.Configuration class is the original MIP SDK representation of the configuration. Opposite to the two above it can mainly be used for reading configuration, not changing it, and in most cases the SDK will load the entire configuration after login and thus have it available in memory when you do queries on it. So after initial load this will surely be the fastest, but on large systems you might experience quite an overhead in the initial loading - especially if you don’t need to read the entire configuraton.

Thanks for the clarifications :+1: