Improving SOAP client performance

bsoremsugar —  October 29, 2008 — 10 Comments

With the Web Services that SugarCRM provides, there are many clients being written to connect to Sugar servers via the SOAP services called SugarSoap.  This article outlines how to improve SOAP performance by caching the SugarSoap WSDL to reduce the overhead on the Sugar server.  Unless you have a specific reason to do otherwise, everybody should implement this approach when writing a SOAP client that connects to SugarSoap.

The example below uses the NuSOAP library for PHP.  The implementation principle of caching the WSDL applies however to whatever client-side SOAP library you are using.

This example code is what I typically have seen and does not cache the WSDL.

$soapurl = 'http://localhost/soap.php?wsdl';  // Note the wsdl parameter
$soapClient = new nusoapclient($soapurl, true);
$soapClient->call('login',
array('user_auth' =>
array('user_name' => 'admin',
'password' => '1234',
'version' => '.01'),
'application_name' => 'SoapTest')
);

This approach passes the wsdl parameter as part of the SOAP URL and then makes subsequent method calls. This is a very inefficient way of calling SugarSoap as for every method call, the WSDL needs to be generated on the Sugar server which results in a slower than necessary response and an extra load on the server.

The following approach caches the WSDL file on the client-side and is a more efficient way of writing a SOAP client to get a faster response.

$soapurl = 'http://localhost/soap.php?wsdl';
$cache = new wsdlcache('C:temp', 12000);

The above line is the important one. The first parameter is the location where you will be searching for the WSDL file and next parameter is cache life time in seconds or 0 for unlimited.

$wsdl = $cache->get($soapurl );
if (is_null($wsdl)) {
$wsdl = new wsdl($soapurl );
$cache->put($wsdl);
}
$soapClient = new nusoapclient($wsdl, true);
$soapClient->call('login',
array('user_auth' =>
array('user_name' => 'admin',
'password' => '1234',
'version' => '.01'),
'application_name' => 'SoapTest')
);

So in this scenario, you are caching the WSDL after the first call.  Subsequent calls to the Sugar server won’t download the WSDL again and again. Your client code will rather pull the WSDL from your local cache.

My testing has shown that this approach improves the response time by 40% – 50%.

Note that the SoapClient class built into PHP 5 automatically caches the WSDL.

Any comments or code on how to do the above using other languages like JAVA or .net are much appreciated.

10 responses to Improving SOAP client performance

  1. 

    Thnx for that ghandi.

    Is this technique also used in bugs.sugarcrm.com?

  2. 

    Thnx for that ghandi.

    Is this technique also used in bugs.sugarcrm.com?

  3. 

    Live saving stuff, thanks for the great pointers. Speed is one of the most important issues in the soap api. Speeding up my sugar soap client applications is going to make me and a lot of my users very happy.

  4. 

    Live saving stuff, thanks for the great pointers. Speed is one of the most important issues in the soap api. Speeding up my sugar soap client applications is going to make me and a lot of my users very happy.

  5. 

    As you asked at the end of your post, do you know how I could do that in .net?
    I don’t know anything about PHP and it’s hard for me to transcribe it. By the way, is there any good pages about SugarSoap in .Net?
    Thanks a lot.

  6. 

    As you asked at the end of your post, do you know how I could do that in .net?
    I don’t know anything about PHP and it’s hard for me to transcribe it. By the way, is there any good pages about SugarSoap in .Net?
    Thanks a lot.

  7. 

    Excellent article!!! it saves like 2 seconds.
    Remember to add this line at the begging:

    require_once(‘include/nusoap/class.wsdlcache.php’);

    so you can create wsdlcache objects without problems.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s