Speeding up a website with soapy nutrition

We are currently studying some performance tuning on a website that is heavily dependent on the Soap web service. But ... our servers are located in Belgium, and the web service we connect to is located in San Francisco, so this means that long distance communications will be minimal.

Our site runs on PHP using the PHP built-in SoapClient class. On average, a web service call takes 0.7 seconds, and we make about 3-5 requests per page. All possible request / response caching has already been implemented, so we are now considering other ways to improve the connection speed.

This is the code that creates the SoapClient instance, and now I'm looking for other ways / methods to increase the speed of individual requests. Anyone have any ideas 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; } 
+4
source share
6 answers

So, the root problem is the request number you need to make. How to create grouped services?

  • If you are responsible for web services, you can create specialized web services that perform several operations at the same time, so your main application can just make one request per page.
  • If you can’t move the application server next to SF.
  • If moving the entire server is not possible, and you cannot create new specialized web services, you can add a bridge located next to the webservices server. This bridge would provide specialized web services and be responsible for calling atomic web services. Instead of 0.7s * 5, you will have 0.7 + 5 * 0.1, for example.
+5
source

PHP.INI

 output_buffering = On output_handler = ob_gzhandler zlib.output_compression = Off 
+3
source

Did you know that network latency slows down every request? As Benoit notes, 0.7 seconds seems like a long round. I would look at some benchmarking - you can do it with curls, although I'm not sure how this will work with your soap client.

Sort of:

 $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 containing the elements for total_time , namelookup_time , connect_time , pretransfer_time , starttransfer_time and redirect_time . From this, you should be able to decide whether they will be dns, request, the actual soap server or the response that takes time.

One obvious thing that just came up for me is that you are requesting a SOAP server through a domain or IP address? If you use a domain, your dns can significantly slow down the process (although it will be cached in several stages). Check the local DNS time (in your client soap or php.ini - not sure) and the TTL of your domain (in your DNS zone). Configure a static IP address for your SanFran server and specify it this way if it has not already been.

+3
source

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

+2
source

1 You can claim that your soap server uses gzip compression for http content, as well as the output of your site. Rounding 0.7 s to SF seems a bit long, or the webservice is responding for a long time, or there is an important latency of work. If you can, try other hosting companies for your Belgian server, in France some of them got a much better connection with the USA than others. I was faced with moving the website from one site to another, and the latency between Paris and New York almost doubled! it is huge and my client with a lot of American visitors was unhappy with this. The decision to move the web server to SF may be an option, you will get much better communication between the servers, but be careful with a delay if your visitors are mainly located in Europe.

2 You can use the mecanism of the operation code cache, for example xcache or APC. This will not change the latency of the soap, but will improve the php runtime.

3 Depending on whether the soap request is repetitive and how long the content update can be extended, you can give it a real improvement by using the cache for soap results. I suggest you use a memory caching system (e.g. xcache / memcached or something else) because they are much faster than files or a database caching system.

From your class, the createclient method is not the most adapted functionality for caching, but for any read operation, this is the best way for perf:

 private function _createClient() { $xcache_key = 'clientcache' if (!xcache_isset($key)) { $ttl = 3600; //one hour cache lifetime $client = $this->_getClient(); ///private method embedding your soap request xcache_set($xcache_key, $client, $ttl); return $client; } //return result form mem cache return xcache_get($xcache_key); } 

An example for the xcache extension, but you can use other systems in a very similar way.

4 To continue, you can use similar mecanism to cache your php processing results (for example, outputting template rendering and other subsequent operations). The key to success in this technique is that you know exactly which part is cached and how long it will remain without problems.

+1
source

Any opportunity to use the AJAX interface. If requests can occur in the background, you will not have to wait for a response.

-1
source

Source: https://habr.com/ru/post/1306807/


All Articles