加速肥皂驱动的网站
我们目前正在考虑对一个严重依赖 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
因此,根本问题是您必须执行的请求数量。创建分组服务怎么样?
So, the root problem is number of request you have to do. What about creating grouped services ?
PHP配置文件
PHP.INI
您确定是网络延迟减慢了每个请求吗?正如伯努瓦所说,0.7 秒似乎是一个很长的回合时间。我会考虑做一些基准测试 - 你可以使用curl 来做到这一点,尽管我不确定这将如何与你的soap 客户端一起工作。
类似于:
$info
将返回一个数组,其中包含total_time
、namelookup_time
、connect_time
、pretransfer_time 的元素
、starttransfer_time
和redirect_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:
$info
will return an array including elements fortotal_time
,namelookup_time
,connect_time
,pretransfer_time
,starttransfer_time
andredirect_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.
通过使用缓存和 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
1 您可以断言您的肥皂服务器使用 gzip 压缩 http 内容,以及您的站点输出。 SF 的 0.7 秒综述似乎有点长,要么是 Web 服务回答时间太长,要么是存在重要的网络延迟。
如果可以的话,尝试一下其他托管公司的比利时服务器,在法国,有些公司与美国的连接比其他公司好得多。
我经历过将网站从一个主机移到另一个主机,巴黎和纽约之间的网络延迟几乎翻了一番!实在是太糟糕了,我的客户和很多美国游客对此并不满意。
将网络服务器迁移到 SF 的解决方案是一种选择,您将在服务器之间获得更好的连接,但如果您的访问者主要位于欧洲,请注意延迟。
2 您可以使用操作码缓存机制,例如 xcache 或 APC。它不会改变soap延迟,但会提高php的执行时间。
3 根据肥皂请求是否重复以及内容更新可以延长多长时间,您可以使用肥皂结果缓存对其进行真正的改进。我建议您使用内存缓存系统(例如 xcache/memcached 或其他),因为它们是比文件或数据库缓存系统快得多。
从您的班级来看, createclient 方法并不是最适合缓存的示例功能,但对于任何读取操作来说,它只是执行的最佳方式:
该示例适用于 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 :
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.
任何使用 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.