Community
Showing results for 
Search instead for 
Do you mean 
Reply

Get Contacts by ID, ridiculously slow (C#)

Accepted Solution Solved
Copper Super Contributor
Posts: 28
Country: Canada
Accepted Solution

Get Contacts by ID, ridiculously slow (C#)

Ok so I have a method in C# that grabs the id of a user and then returns it. I currently am comparing a set of contacts from a web request  with a set of contacts from ACT (which returns a json object of contacts and respective data) in order to see which is more recent. 

 

The ACT ID is stored on the web as well, as a result I get this from the returned data and then send it to my method, which grabs the contact with the same ID in ACT.

 

It works, however it takes an insane amount of time to complete (like an hour). I'm not sure if there is a more effecient way of doing so, or if it is the limitation of the computer act is currently hosted on. There are 5k + contacts.

 

This is my method:

 

 public ContactList getContactById(string id)
        {
            ACTFM.LogOn((path), user, pass);
            Guid[] gArray = new Guid[1];
            gArray[0] = Guid.Parse(id);
            ContactList contactByID = null;

            try
            {
                contactByID = ACTFM.Contacts.GetContactsByID(null, gArray);
                //ContactList contactByName = ACTFM.GetContactsByEmail(null, gArray);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            return contactByID;
      }

 

Any guidence to speeding up the process would be greatly appreciated.


Accepted Solutions
Solution
Accepted by topic author 2gen
‎09-25-2015 03:20 AM
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Get Contacts by ID, ridiculously slow (C#)

P.S.  Since I'm not actually doing anything with the contacts I get it's quite a bit faster than my original minute estimate.  If I retrieved a field value I would expect it to take a little longer.  I just tested it to see how long that would take and retrieving the contents of the ID/Status field for each contact took 11.64 seconds when I added it to the loop.  If I were retrieving information in a related table like address or email it would probably take longer and updating a field would probably take longer still.  Nonetheless we're still quite a bit faster than your 5 minutes.  I'm sure you can figure out where the bottleneck is and fix it.  Good luck!

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!

View solution in original post


All Replies
Copper Elite Contributor
Posts: 81
Country: Canada

Re: Get Contacts by ID, ridiculously slow (C#)

Is there a reason you are logging on to the Act framework each time you need a Contact by ID? I feel like that is probably what is causing your issue. Call the Logon method at the start of your application and it should stay logged on as long as the "ACTFM" variable is not disposed.

Ahsan Khalid

Chief Technology Officer
Keystroke Quality Computing Inc.
www.keystroke.ca

Copper Super Contributor
Posts: 28
Country: Canada

Re: Get Contacts by ID, ridiculously slow (C#)

I've changed this so the logon happens application wide (in a class constructor) instead of on each method instance and it still is taking ridiculously long.

Silver Super Contributor
Posts: 2,328
Country: USA

Re: Get Contacts by ID, ridiculously slow (C#)

If I write a routine to retrieve contacts by id and just loop through 5000 or so ids I would expect it to take about a minute.  I would add a few stopwatches to your app and see if you can figure out where the delay is.  Get contact by id is one of the fastest methods out there.  I'll test it with 5000 ids if you'd like me to and give you some real numbers.


Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 28
Country: Canada

Re: Get Contacts by ID, ridiculously slow (C#)

It would be nice to compare results so I can get a decent benchmark on what to expect. It takes around 5 minutes in total. I'll look into applying you stopwatch suggestion and get back to you.

 

Thanks!

Silver Super Contributor
Posts: 2,328
Country: USA

Re: Get Contacts by ID, ridiculously slow (C#)

I used your routine with the stopwatch and here are the results I got for retrieving 5000 contactlists from an array that has one guid in it:  Elapsed = {00:00:02.4513622}

 

So it only took me 2.45 seconds to retrieve them.  I'm not doing anything with them just looping through them but I used your code so the performance problem is elsewhere.  I'm running Act! v16.2 on this machine.

 

First I retrieved a list of 150,000 contacts and then looped through them creating a guid array with 5000 entries in it.  That took:  Elapsed {00:00:02.1083260}  or just 2.1 seconds.

 

I suspect that most of the time in the routine is actually spent converting the string to a guid!

 

This is the code I'm using:

 


private void ContactIDTest()
{
 Guid[] guid = new Guid[1];
 Stopwatch thisStopwatch = new Stopwatch();
 thisStopwatch.Start();
 ContactList cList = ActFwk.Contacts.GetContacts(null);
 for (int i = 0; i <= 5000; i++) {
  guid(i) = cList(i).ID;
  Array.Resize(guid, guid.Length + 1);
 }
 thisStopwatch.Stop();
 Stopwatch myStopwatch = new Stopwatch();
 myStopwatch.Start();
 for (int i = 0; i <= 5000; i++) {
  cList = getContactById(guid(i).ToString);
 }
 myStopwatch.Stop();
}

public ContactList getContactById(string id)
{
 //ACTFM.LogOn((Path), user, pass)
 Guid[] gArray = new Guid[1];
 gArray(0) = Guid.Parse(id);
 ContactList contactByID = null;

 try {
  //ContactList contactByName = ACTFM.GetContactsByEmail(null, gArray);
  contactByID = ActFwk.Contacts.GetContactsByID(null, gArray);
 } catch (Exception ex) {
  Debug.WriteLine(ex.ToString());
 }
 return contactByID;
}

 

Stan

 

 


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Solution
Accepted by topic author 2gen
‎09-25-2015 03:20 AM
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Get Contacts by ID, ridiculously slow (C#)

P.S.  Since I'm not actually doing anything with the contacts I get it's quite a bit faster than my original minute estimate.  If I retrieved a field value I would expect it to take a little longer.  I just tested it to see how long that would take and retrieving the contents of the ID/Status field for each contact took 11.64 seconds when I added it to the loop.  If I were retrieving information in a related table like address or email it would probably take longer and updating a field would probably take longer still.  Nonetheless we're still quite a bit faster than your 5 minutes.  I'm sure you can figure out where the bottleneck is and fix it.  Good luck!

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!