WSDL Caching is first introduced with the WSF/PHP 2.0.0 release to optimize the response time of PHP web services. In WSDL Caching WSF/PHP keeps an intermediate XML model which is generated from the WSDL in memory. This intermediate model which we call as ‘SIG’ or ‘Signature’ model is generated at the first request to the service. This SIG can be generated using an XSLT template from any WSDL 2.0. So if you provide a WSDL version 1.1, WSF/PHP first convert it to a WSDL 2.0 using another XSLT template and then generate the SIG model. So in generally when WSDL caching is used it avoids two XSLT parses and hence optimize the response time significantly.
In this blog, I will show you a result of some performance tests I did to measure the response time of a service with and without WSDL Caching.
The complete source codes used for the test can be found from here.
Here is a part of the service script I used. It is a simple echo service that echo a string.
// create service in WSDL mode $service = new WSService(array ("wsdl" =>"echo.wsdl", "cacheWSDL" => false, // By default cache WSDL is true "actions" => $actions, "operations" => $operations)); // getting the start_time $start_time = microtime(true); // process client requests and reply $service->reply(); // getting the end time $end_time = microtime(true); // getting the time difference $time_diff = $end_time - $start_time; logme($time_diff);
You can see in there I have set the “cacheWSDL” to false and log the time taken by the $service->reply() function. Later I have set the “cacheWSDL” to true and measure the time again for the comparison with earlier values.
I have written a client to invoke the service 10 times. And I’m going to measure the time taken do the client request in there.
for($i = 1; $i <= 10; $i ++) { // create client in WSDL mode $client = new WSClient(array ("wsdl" =>"echo.wsdl")); // get proxy object reference form client $proxy = $client->getProxy(); // create input object and set values //TODO: fill $input with (data type: string) data to match your business logic $input = "Hello World"; // getting the start_time $start_time = microtime(true); // call the operation $response = $proxy->myEcho($input); //TODO: Implement business logic to consume $response, which is of type string // getting the end time $end_time = microtime(true); // getting the time difference $time_diff = $end_time - $start_time; logme($time_diff); echo $response."</br>"; }
Then I have measured the time taken to first 10 request for both WSDL caching on and off scenarios just after starting the Apache server.
Without WSDL Caching | With WSDL Caching | ||
WSClient Operation invocation $client->myEcho($input) |
WSService reply $service->reply() |
WSClient Operation invocation $client->myEcho($input) |
WSService reply $service->reply() |
0.11091995239258 | 0.074313163757324 | 0.15158987045288 | 0.11872982978821 |
0.082005977630615 | 0.06772780418396 | 0.046205997467041 | 0.035470008850098 |
0.082638025283813 | 0.072394132614136 | 0.044647932052612 | 0.028353929519653 |
0.079883098602295 | 0.06883692741394 | 0.037378072738647 | 0.026839017868042 |
0.082012176513672 | 0.068314790725708 | 0.046517133712769 | 0.035148859024048 |
0.074619054794312 | 0.063674211502075 | 0.041852951049805 | 0.027253866195679 |
0.084127187728882 | 0.071602821350098 | 0.041593074798584 | 0.027820825576782 |
0.081571102142334 | 0.066971063613892 | 0.057910919189453 | 0.038385152816772 |
0.087567090988159 | 0.073211193084717 | 0.043420076370239 | 0.02738094329834 |
0.078658103942871 | 0.064589977264404 | 0.050504922866821 | 0.037022113800049 |
If you obvious these values you will figure out when you don’t use WSDL caching it takes same amount of time to server each request. But when you turn on WSDL caching it takes a little more time at the very first request, but the subsequent requests take very low values.
Here is the chart for the above Data, See the Green and White lines corresponding to the WSDL caching turn on, have taken low values. In average we can observe a 50% reduction in server response time with the WSDL caching.
This result is for a very simple WSDL which only had an echo operation. When the WSDL get more complex and contain lot of wsdl/schema includes and imports, we can expect more optimization due to the WSDL caching. We will check how the complexity of the WSDL affect the performance in a later blog post.:)