Discussion
Vikram Rajput · Feb 15

IRIS Native API for .NET performance issue

I am surprised with the performance (poor) of Native API for .NET

       Following code (where ^testGlobal,node1 has 50 records) takes 5 seconds to run.  Anyone else think there is room for the improvement? 

    string global = "^testGlobal";
            object[] Subs = new object[1];
            Subs[0] = "node1";

            try
            {
                IRISIterator iter = iris.GetIRISIterator(global, Subs); 
               foreach (var item in iter)
                {        
                    Console.WriteLine((string)(iter.CurrentSubscript));
                }               

            }
            catch (Exception ex)
            {

            }
0
0 305
Discussion (8)2
Log in or sign up to continue

I think we need a bit more info about your data structure and your environment. 

I built the following little program on my mac with .NET 5  and it runs really fast (reported as 0 ms).  The data structure in my example, as you can see, is incredibly simple, so that might be the source of performance differences.  I'm also running on localhost, which could be different on your setup.

 

using System;
using InterSystems.Data.IRISClient;
using InterSystems.Data.IRISClient.ADO;

public class IRISNative
{
    public static void Main(String[] args) 
    {
        try {
            IRISConnection conn = new IRISConnection();
            conn.ConnectionString = "Server=localhost; Port=1972; Namespace=User; Password=...; User ID=...; SharedMemory=false; logfile=./dbnative.log";
            conn.Open();

            IRIS iris = IRIS.CreateIRIS(conn);

            Console.WriteLine("[1. Populating the data]");
            string global = "^testGlobal";
            object[] Subs = new object[1];
            Subs[0] = "node1";

            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            for (var i=0; i<50; i++) {
                iris.Set(i, global, Subs[0], "node"+i);
            }
            watch.Stop();
            Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");

            Console.WriteLine("[2. Querying the data]");
            watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            IRISIterator iter = iris.GetIRISIterator(global, Subs);
            foreach (var item in iter)
            {
                Console.WriteLine((string)(iter.CurrentSubscript));
            }
            watch.Stop();
            Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");

            iris.Close();
            conn.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

Thanks for the quick response.

Yes, data structure is different and I was running over the network. Let me remove those variables and run few more tests.

I will get back to you soon.

Bob,

You are getting 0ms because you did not start the StopWatch :)

Can you please add that to your code and test it at your end?

var watch = new System.Diagnostics.Stopwatch();
 watch.Start();

It runs in only 10 milliseconds (less if I don't actually print to console) on my machine.

But the time is nowhere near the 5 seconds in your original post, which is why I think we need to know more about your application.  If you take the same code as above what timing do you see?

Even your exact code is taking close to 3.5 seconds for me. I am running the code remotely compare to your localhost. 

Which evidently proves that you have  to chase a network performance  problem   ( !! REMOTELY !!)
and not a problem in the code of the API.