Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up a soap powered website

We're currently looking into doing some performance tweaking on a website which relies heavily on a Soap webservice. But ... our servers are located in Belgium and the webservice we connect to is locate in San Francisco so it's a long distance connection to say the least.

Our website is PHP powered, using PHP's built in SoapClient class. On average a call to the webservice takes 0.7 seconds and we are doing about 3-5 requests per page. All possible request/response caching is already implemented so we are now looking at other ways to improved the connection speed.

This is the code which instantiates the SoapClient, what i'm looking for now is other ways/methods to improve speed on single requestes. Anyone has idea's or suggestions?

private function _createClient()
{
    try {

        $wsdl = sprintf($this->config->wsUrl.'?wsdl', $this->wsdl);
        $client = new SoapClient($wsdl, array(
            'soap_version'       => SOAP_1_1,
            'encoding'           => 'utf-8',
            'connection_timeout' => 5,
            'cache_wsdl'         => 1,
            'trace'              => 1,
            'features'           => SOAP_SINGLE_ELEMENT_ARRAYS
        ));

        $header_tags = array('username' => new SOAPVar($this->config->wsUsername, XSD_STRING, null, null, null, $this->ns),
                             'password' => new SOAPVar(md5($this->config->wsPassword), XSD_STRING, null, null, null, $this->ns));
        $header_body = new SOAPVar($header_tags, SOAP_ENC_OBJECT);
        $header = new SOAPHeader($this->ns, 'AuthHeaderElement', $header_body);

        $client->__setSoapHeaders($header);

    } catch (SoapFault $e){
        controller('Error')->error($id.': Webservice connection error '.$e->getCode());
        exit;
    }

    $this->client = $client;
    return $this->client;
}
like image 304
ChrisR Avatar asked Apr 13 '10 13:04

ChrisR


4 Answers

So, the root problem is number of request you have to do. What about creating grouped services ?

  • If you are in charge of the webservices, you could create specialized webservices which do multiple operations at the same time so your main app can just do one request per page.
  • If not you can relocate your app server near SF.
  • If relocating all the server is not possible and you can not create new specialized webservices, you could add a bridge, located near the webservices server. This bridge would provide the specialized webservices and be in charge of calling the atomic webservices. Instead of 0.7s * 5 you'd have 0.7s + 5 * 0.1 for example.
like image 174
Arkh Avatar answered Nov 18 '22 14:11

Arkh


PHP.INI

output_buffering = On
output_handler = ob_gzhandler
zlib.output_compression = Off
like image 26
Brant Messenger Avatar answered Nov 18 '22 16:11

Brant Messenger


Do you know for sure that it is the network latency slowing down each request? 0.7s seems a long round time, as Benoit says. I'd look at doing some benchmarking - you can do this with curl, although I'm not sure how this would work with your soap client.

Something like:

$ch = curl_init('http://path/to/sanfrancisco/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$info = curl_getinfo($ch);

$info will return an array including elements for total_time, namelookup_time, connect_time, pretransfer_time, starttransfer_time and redirect_time. From these you should be able to work out whether it's the dns, request, the actual soap server or the response that's taking up the time.

One obvious thing that's just occurred to me is are you requesting the SOAP server via a domain or an IP? If you're using a domain, your dns might be slowing things down significantly (although it will be cached at several stages). Check your local dns time (in your soap client or php.ini - not sure) and the TTL of your domain (in your DNS Zone). Set up a static IP for your SanFran server and reference it that way if not already.

like image 3
Adam Hopkinson Avatar answered Nov 18 '22 15:11

Adam Hopkinson


Optimize the Servers (not the client!) HTTP response by using caching and HTTP compressing. Check out the tips at yahoo http://developer.yahoo.com/performance/rules.html

like image 2
powtac Avatar answered Nov 18 '22 15:11

powtac