加速肥皂驱动的网站

发布于 2024-08-28 12:20:31 字数 1477 浏览 6 评论 0原文

我们目前正在考虑对一个严重依赖 Soap Web 服务的网站进行一些性能调整。但是......我们的服务器位于比利时,我们连接的网络服务位于旧金山,因此至少可以说这是一个长途连接。

我们的网站由 PHP 驱动,使用 PHP 内置的 SoapClient 类。 平均而言,对 Web 服务的调用需要 0.7 秒,并且我们每个页面执行大约 3-5 个请求。所有可能的请求/响应缓存都已实现,因此我们现在正在寻找其他方法来提高连接速度。

这是实例化 SoapClient 的代码,我现在正在寻找的是提高单个请求速度的其他方式/方法。有人有想法或建议吗?

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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

孤千羽 2024-09-04 12:20:31

因此,根本问题是您必须执行的请求数量。创建分组服务怎么样?

  • 如果您负责 Web 服务,您可以创建专门的 Web 服务,同时执行多个操作,这样您的主应用程序就可以在每个页面执行一个请求。
  • 如果没有,您可以将您的应用程序服务器重新安置在 SF 附近。
  • 如果无法重新定位所有服务器并且无法创建新的专用 Web 服务,则可以添加位于 Web 服务服务器附近的桥接器。该桥将提供专门的 Web 服务并负责调用原子 Web 服务。例如,您将拥有 0.7s + 5 * 0.1,而不是 0.7s * 5。

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.
懒的傷心 2024-09-04 12:20:31

PHP配置文件

output_buffering = On
output_handler = ob_gzhandler
zlib.output_compression = Off

PHP.INI

output_buffering = On
output_handler = ob_gzhandler
zlib.output_compression = Off
樱花细雨 2024-09-04 12:20:31

您确定是网络延迟减慢了每个请求吗?正如伯努瓦所说,0.7 秒似乎是一个很长的回合时间。我会考虑做一些基准测试 - 你可以使用curl 来做到这一点,尽管我不确定这将如何与你的soap 客户端一起工作。

类似于:

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

$info 将返回一个数组,其中包含 total_timenamelookup_timeconnect_timepretransfer_time 的元素starttransfer_timeredirect_time。从这些中,您应该能够确定是否是 dns、请求、实际的肥皂服务器或响应占用了时间。

我刚刚想到的一件明显的事情是您是通过域还是 IP 请求 SOAP 服务器?如果您使用的是域名,您的 dns 可能会显着减慢速度(尽管它会在几个阶段进行缓存)。检查您的本地 dns 时间(在您的肥皂客户端或 php.ini 中 - 不确定)和域的 TTL(在您的 DNS 区域中)。为您的 SanFran 服务器设置一个静态 IP,并以这种方式引用它(如果还没有的话)。

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.

勿忘初心 2024-09-04 12:20:31

通过使用缓存和 HTTP 压缩来优化服务器(而不是客户端!)HTTP 响应。查看 yahoo 上的提示 http://developer.yahoo.com/performance/rules.html< /a>

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

夜深人未静 2024-09-04 12:20:31

1 您可以断言您的肥皂服务器使用 gzip 压缩 http 内容,以及您的站点输出。 SF 的 0.7 秒综述似乎有点长,要么是 Web 服务回答时间太长,要么是存在重要的网络延迟。
如果可以的话,尝试一下其他托管公司的比利时服务器,在法国,有些公司与美国的连接比其他公司好得多。
我经历过将网站从一个主机移到另一个主机,巴黎和纽约之间的网络延迟几乎翻了一番!实在是太糟糕了,我的客户和很多美国游客对此并不满意。
将网络服务器迁移到 SF 的解决方案是一种选择,您将在服务器之间获得更好的连接,但如果您的访问者主要位于欧洲,请注意延迟。

2 您可以使用操作码缓存机制,例如 xcache 或 APC。它不会改变soap延迟,但会提高php的执行时间。

3 根据肥皂请求是否重复以及内容更新可以延长多长时间,您可以使用肥皂结果缓存对其进行真正的改进。我建议您使用内存缓存系统(例如 xcache/memcached 或其他),因为它们是比文件或数据库缓存系统快得多。

从您的班级来看, createclient 方法并不是最适合缓存的示例功能,但对于任何读取操作来说,它只是执行的最佳方式:

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);
}

该示例适用于 xcache 扩展,但您可以以非常类似的方式使用其他系统

4 更进一步,您可以使用类似的机制来缓存 php 处理结果(例如模板渲染输出和其他资源消耗操作)。这项技术成功的关键是准确地知道哪个部分被缓存以及它将在不刷新的情况下保留多长时间。

1 You can assert your soap server use gzip compression for http content, as well as your site output does. A 0,7s roundup to SF seems a bit long, it's either webservice is long to answer, either there is an important natwork latency.
If you can, give a try to other hosting companies for your belgium server, in France some got a far better connectivity to the US than others.
I experienced to move a website from one host o another and network latency between Paris and New york has almost doubled ! it's uge and my client with a lot of US visitors was unhappy with it.
The solution of relocating web server to SF can be an option, you'll get a far better connectivity between servers, but be careful of latency if your visitors are mainly located in Europe.

2 You can use an opcode cache mecanism, such as xcache or APC. It wil not change the soap latency, but will improve php execution time.

3 Depending if soap request are repetitive, and how long could a content update could be extended, you can give it a real improvement using cache on soap results. I suggest you to use in-memory caching system (Like xcache/memcached or other) because they're ay much faster than file or DB cache system.

From your class, the createclient method isn't the most adapted exemple functionality to be cached, but for any read operation it's just the best way to 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);
}

The example is for xcache extension, but you can use other systems in a very similar manner

4 To go further you can use similar mecanism to cache your php processing results (like template rendering output and other ressource consumming operations). The key to success with this technic is to know exactly wich part is cached and for how long it will stay withous refreshing.

时光礼记 2024-09-04 12:20:31

任何使用 AJAX 界面的机会..如果请求可以在后台发生,您似乎就不会等待响应。

Any chance of using an AJAX interface.. if the requests can be happening in the background, you will not seem to be left waiting for the response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文