1

I am going with the Entity Framework code first approach and am finding that queries to grab just 350 records or so is taking about 8 seconds. How can I speed this up? Is this Universe or Entity Framework that is being slow?

Entity Framework 5.0 U2.Data.Client 1.2.1 .Net Framework 4.5.1

RAMContext looks something like this :

public class RAMContext : DbContext
{
    public RAMContext() { }

    public DbSet<Policy> Policies { get; set; }
}

Here is the code to grab the entities :

List<Policy> policies = null;

Database.SetInitializer<RAMContext>(null);
using (RAMContext context = new RAMContext())
{
    policies = (from p in context.Policies
               where p.AGENT_NO == id
               select p).ToList();
}

Here is the connection string :

<add name="RAMContext" connectionString="Database=<account>;UserID=<userid>;Password=<pwd>;Server=<server>;Pooling=false;ServerType=universe;ConnectTimeout=360;SleepAfterClose=300;PersistSecurityInfo=true" providerName="U2.Data.Client" />

AGENT_NO is indexed and the same query ran directly on the DB from TCL finishes almost instantly.

EDITED After the comments from Rajan I tried the following :

policies = (from p in context.Policies
            where p.AGENT_NO == id
            select new PolicyModel
            {
                //Type = PolicyModel.Types)StringValue.GetEnumValueByStringValue(typeof(PolicyModel.Types), p.TYPE),
                Insured = p.INSURED,
                City = p.CITY,
                State = p.STATE,
                CancelDate = p.CANC_DT
                //IsNew = PickHelper.PickYNNullToBool(p.NEW_RENEW_FLG)
            });

I am able to make this select in under 3 seconds now, it appears. I also rebuilt the index on AGENT_NO and I believe that helped considerably.

Trying your second suggestion I get the following exception :

An exception of type 'System.IndexOutOfRangeException' occurred in U2.Data.Client.dll but was not handled in user code

Additional information:

Invalid index -1 for this U2ParameterCollection with Count=0.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
sourkrause
  • 178
  • 8
  • How does it compare to running the same query against the DB? is there an Index on `AGENT_NO` ? – Christian Phillips Jun 03 '14 at 16:00
  • Could you please try only few columns (int, string)? For example: var q = (from p in ctx.Customers where p.CUSTID >0 select new { ID = p.CUSTID, NAME=p.FNAME }); Do you see any difference? – Rajan Kumar Jun 03 '14 at 18:28
  • Could you please try on more thing? Please run the following code (without EF). For example. // take start time U2Command cmd = con.CreateCommand(); cmd.CommandText = "SELECT ID, FNAME FROM CUSTOMER"; DataSet ds = new DataSet(); U2DataAdapter da = new U2DataAdapter(cmd); da.Fill(ds); //take end time – Rajan Kumar Jun 03 '14 at 18:33
  • I don't know universe well enough to even know if has indices with included columns, but that could definitely be an idea if it does, as a general DB principle. So perhaps could ordering on some indexed column (even if it's utterly arbitrary). The Linq itself doesn't have anything alarming about it, though if the `List` isn't actually necessary (you aren't hitting it more than once), you could skip that and just iterate through the results. – Jon Hanna Jun 03 '14 at 20:53
  • What is your SQL Syntax? Does it contain “@ASSOC_ROW”? Try putting “NamedParameters=false” in connection string. If it does not solve, then send me the log file. Recently I have solved this issue in U2 Toolkit for .NET v2.1.0. We will Release v2.1.0 very soon. I think you have missed the BETA. Please read: http://blog.rocketsoftware.com/2014/05/access-nosql-data-using-sql-syntax-u2-toolkit-net-v2-1-0-beta/ http://blog.rocketsoftware.com/2014/05/create-asp-net-web-api-using-multivalue-net-provider/ – Rajan Kumar Jun 03 '14 at 23:16
  • Please read: http://blog.rocketsoftware.com/2014/05/access-nosql-data-using-sql-syntax-u2-toolkit-net-v2-1-0-beta/ – Rajan Kumar Jun 03 '14 at 23:18
  • I am able to get this to run quite a bit faster now after rebuilding the indexes. It's still taking 6 seconds in the worst case it seems. NamedParameters=false didn't seem to speed it up. I will play around some more with my models and see if I can't un-complicate this as much as possible and see how fast I can get it. As far as the BETA for v2.1.0, I should be included in that. I talked to a guy at Rocket who was supposed to get me in on it. If not, I would love to be. – sourkrause Jun 04 '14 at 16:52
  • See below my comment in “answer section” . For BETA, please send an email to u2askus@rocketsoftware.com . – Rajan Kumar Jun 05 '14 at 04:24

1 Answers1

0

Could you please try the following code? This code does not use Entity Framework (LINQ to Entity). We want to see how UniVerse is behaving without Entity Framework.

You need to do the following:

  • Create C# Console application
  • Replace Program.cs file’ s content with the following code
  • Right Click->Add Reference -> C:\Program Files (x86)\Rocket Software\U2 Toolkit for .NET\U2 Database Provider\bin.NETFramework\v4.0\U2.Data.Client.dll
  • Change connection string
  • Change SQL syntax
  • Run the program. See below screen shot. It shows “Time Taken in Seconds”.

Code



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using U2.Data.Client;
    using System.Data;
    using System.Diagnostics;

    namespace DataAdapter
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    Console.WriteLine("start.........................");
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
                    conn_str.UserID = "administrator";
                    conn_str.Password = "pass";
                    conn_str.Server = "localhost";
                    conn_str.Database = "XDEMO";
                    conn_str.ServerType = "UNIVERSE";
                    conn_str.Pooling = false;
                    string s = conn_str.ToString();
                    U2Connection con = new U2Connection();
                    con.ConnectionString = s;

                    con.Open();
                    Console.WriteLine("Connected...");
                    U2Command cmd = con.CreateCommand();
                    cmd.CommandText = "SELECT * FROM PRODUCTS";
                    DataSet ds = new DataSet();
                    U2DataAdapter da = new U2DataAdapter(cmd);
                    da.Fill(ds);

                    sw.Stop();

                    TimeSpan elapsed = sw.Elapsed;
                    string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", elapsed.Hours, elapsed.Minutes, elapsed.Seconds, elapsed.Milliseconds / 10);
                    int nSec = elapsed.Seconds;
                    con.Close();
                    Console.WriteLine("Time Taken in seconds:" + elapsedTime);
                    Console.WriteLine("End........................... ");

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                }
                finally
                {
                    Console.WriteLine("Enter to exit:");
                    string line = Console.ReadLine();
                }
            }
        }
    }


enter image description here

Rajan Kumar
  • 718
  • 1
  • 4
  • 9
  • Hi Rajan. Time taken in seconds is 00:00:00.71 selecting about 1300 records. I ran this on the same account I am running the other code. One question, while I'm here; Will the new version of U2.Data.Client be quicker? The application I am developing will not go live for quite some time so I will be updating to that new version asap. – sourkrause Jun 05 '14 at 14:52
  • It is recommended that you should go to higher version ( U2 Toolkit for .NET v2.1.0). You need to wait another one or two weeks. I hope you will see some performance improvement. Did you send email to u2askus@rocketsoftware.com? – Rajan Kumar Jun 05 '14 at 16:43
  • I did. Joseph told me over a month ago he would get me in on the BETA too, so we'll see. Thanks so much for all your help Rajan. If I can't get a good enough performance out of the new Toolkit I will let you know...otherwise I'll have to try use UniObjects and subroutines instead. – sourkrause Jun 05 '14 at 16:55
  • We have Released v2.1.0 on June 10th, 2014. Please try it now. Now we have Native Visual Studio Integration, so you can try in your connection string “AccessMode=Native” also. Please send one more time email to u2askus@rocketsoftware.com and mention “Attention : Rajan Kumar” – Rajan Kumar Jun 16 '14 at 00:44