[Vtigercrm-developers] Creating Contact records via code. Timing results...

Alan Lord alanslists at gmail.com
Wed Nov 26 12:01:32 GMT 2014


I'm in the middle of a major migration for a customer from 5.3.0 to 
6.1.0 and a big architectural change to the way they manage their data.

As part of the migration process I'm creating a bunch of new Contact 
records from a query that returns about 40,000 rows.

It's possible to create records using a couple of methods (at least)...

So I thought I'd do some timings to see which method was faster by 
limiting to 1000 rows. I thought others would find my results interesting.

This one using the "traditional" focus->save() method:
>             echo "Creating Contact $i..." . PHP_EOL;
>             $focus = CRMEntity::getInstance('Contacts');
> 	
>             $focus->column_fields['assigned_user_id'] = $row['smownerid'];
> 	      $focus->column_fields['acclead_id']       = $row['leadid'];
> 	      $focus->column_fields['lastname']         = $row['lastname'];
> 	      $focus->column_fields['title']            = $row['cf_609'];
> 	      $focus->column_fields['phone_ext']        = $row['cf_824'];
> 	      $focus->column_fields['leadsource']       = $row['leadsource'];
>
>             $focus->save('Contacts');
>             echo "Contact saved." . PHP_EOL;

Or using the Server API (Webservices) method:
>             try {
>                 $data = array (
>                             'assigned_user_id' => '19x' . $row['smownerid'],
>                             'acclead_id' => '2x' . $row['leadid'],
>                             'lastname' => $row['lastname'],
>                             'title' => $row['cf_609'],
>                             'phone_ext' => $row['cf_824'],
>                             'leadsource' => $row['leadsource'],
>                 );
>
>                 echo "Creating Contact $i..." . PHP_EOL;
>
>                 $ent = vtws_create('Contacts', $data, $current_user);
>
>                 echo "Contact saved." . PHP_EOL;
>
>             } catch (WebServiceException $ex) {
>                     echo $ex->getMessage();
>             }

I was very surprised by the results!

Webservices Method:
> Creating Contact 999...
> Contact saved.
>
> real    2m22.151s
> user    0m48.923s
> sys     0m5.912s

The focus->save() method:
> Creating Contact 999...
> Contact saved.
>
> real    18m11.130s
> user    1m0.656s
> sys     0m6.800s

So the Webservices method was approximately 9x faster in real-time!

I'd love to know the main reason why it is *so* much quicker?

Cheers

Al



More information about the vtigercrm-developers mailing list