-- umpirsky <[email protected]> wrote
(on Thursday, 23 July 2009, 12:32 AM -0700):
> I have XML-RPC client-server architecture witl Zend_XmlRpc on both, client
> and server side. My app with XML-RPC is 3-5 times slower with XML-RPC
> comparing to same app with pure PHP calls - pretty slow, huh. Some methods
> produce very large XML so I needed to page results in some cases and send in
> chunks. I attach only one server class with near 100 methods.
> 
> I tried to optimize it with caching server definition like on
> http://framework.zend.com/manual/en/zend.xmlrpc.server.html#zend.xmlrpc.server.use.case7
> , but it turned out I got even slower calls then without cache. Any idea
> why?
> 
> I gained some speed by setting _skipSystemLookup to true. Do you think there
> can be some consequences? If I pass empty array for ex?
> 
> Any general tips or idea how I can speed up my server?

This is a known problem, actually, and is due to how PHP handles
reflection.

There is a way around it that's more performant, but not documented. In
1.7, we created Zend_Server_Definition, which is simply a value object
containing the class => method mappings used by the various servers.
Since it's a value object, it does not rely on reflection, and as a
result, when autoloading is on, can be a ton more performant.

Instead of following the directions currently in the manual, do the
following:

  * Use autoloading. This will ensure you don't have to load all classes
    attached to the server on every request
  * Cache the return value of getDispatchTable(). This caches a
    Zend_Server_Definition, which is a value object with simply string
    names for the classes and methods (not callbacks or reflection)
  * On subsequent requests, pass the cached dispatch table to
    loadFunctions().

It might look like this, then:

    require_once 'Zend/Loader/Autoloader.php';
    Zend_Loader_Autoloader::getInstance();

    $server = new Zend_XmlRpc_Server();

    // Fill in your own front/back-end options. Just make sure that
    // autoserialization is on.
    $cache = Zend_Cache::factory('Core', 'File', $frontendOpts, $backendOpts);

    if (!$definition = $cache->load('xmlrpc-dispatch-table')) {
        // Do your server definition here...
        // ...
        // and then cache the dispatch table
        $cache->save($server->getDispatchTable(), 'xmlrpc-dispatch-table');
    } else {
        // Otherwise, load the server definition
        $server->loadFunctions($definition);
    }

    echo $server->handle();

I haven't tested the above, but there *are* unit tests for passing
Zend_Server_Definition to loadFunctions(), so the theory has some basis.
:)

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to