连接到 WCF Web 服务的速度莫名其妙地慢
我的公司目前正在从传统的 ASMX Web 服务过渡到 WCF Web 服务,因为我们需要改进对 WCF 可用的复杂类型的处理。
在调查网页的性能问题时,我发现最大的(在某种程度上)性能缺陷是与 WCF 服务的初始连接。当我说初始时,我的意思是下面的代码,每次调用它时,页面刷新足以获得缓慢的连接:
$client = new SoapClient("<address-to-webservice>",
array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));
对该 Web 服务中的方法的后续调用很快,但连接却莫名其妙地慢。
在同一页面上有一个到同一服务器上托管的 ASMX 服务的连接,该服务的连接速度要快得多。
Connection to WCF Webservice took 1.6509809494019 seconds //(this is just calling new SoapClient)
Connection to ASMX Webservice took 0.24430394172668 seconds
Calling ASMX->Method
ASMX->Method returned in 0.011564970016479 seconds
Calling WCF->Method1
WCF->Method1 returned in 0.011118173599243 seconds
Calling WCF->Method2
WCF->Method2 returned in 0.0038959980010986 seconds
Calling WCF->Method3
WCF->Method3 returned in 0.0041651725769043 seconds
这是在内部网络上运行的,显然从外部连接的速度更慢。正如您所看到的,WCF Web 服务连接速度相当慢。
连接到 WCF Web 服务时是否有办法(显着)提高性能?
更新:
有关 WCF 客户端的一些信息。 托管在 IIS 7、Windows Server 2008 上。 使用 BasicHttpBinding(因为 PHP SoapClient 不支持更复杂的 wsHttpBinding)。 连接使用 ssl。
此外,当通过 WCFStorm 连接时,连接速度要快得多,这让我相信问题可能出在 PHP SoapClient 上。
My company is currently transitioning from traditional ASMX webservices to WCF webservices, because we need the improved handling of complex types available with WCF.
Whilst investigating performance issues with a web page, I have identified that the biggest (by some margin) performance sinkhole is the initial connection to the WCF service. When I say initial, I mean the following bit of code, every time it is called, a page refresh is enough to get a slow connection:
$client = new SoapClient("<address-to-webservice>",
array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));
Subsequent calls to the methods in this webservice are quick, however the connection is inexplicably slow.
On the same page there is a connection to an ASMX service that is hosted on the same server, which connects much much quicker.
Connection to WCF Webservice took 1.6509809494019 seconds //(this is just calling new SoapClient)
Connection to ASMX Webservice took 0.24430394172668 seconds
Calling ASMX->Method
ASMX->Method returned in 0.011564970016479 seconds
Calling WCF->Method1
WCF->Method1 returned in 0.011118173599243 seconds
Calling WCF->Method2
WCF->Method2 returned in 0.0038959980010986 seconds
Calling WCF->Method3
WCF->Method3 returned in 0.0041651725769043 seconds
This is running on an internal network, and obviously connecting from outside is even slower. As you can see the WCF Webservice connection is considerably slower.
Is there a way to improve performance (considerably) when connecting to the WCF webservice?
UPDATE:
Some information about the WCF Client.
Hosted on IIS 7, Windows Server 2008.
Using BasicHttpBinding (as the PHP SoapClient doesn't support the more complex wsHttpBinding).
The connection is using ssl.
Additionally, when connecting via WCFStorm the connection is much faster, leading me to believe the issue is perhaps with the PHP SoapClient.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是根据您在问题中的 WCFStorm 评论进行的猜测,ASMX 版本生成的 WSDL 可能比服务的 WCF 版本更容易解析。我不知道 PHP SoapClient 是否从 WSDL 动态创建代理,但如果 ASMX 与 WCF 生成的 WSDL 显着不同,则可能会导致初始瓶颈。
Just a guess based on your WCFStorm comment in the question, it could be that the WSDL generated by the ASMX version may be easier to parse than the WCF version of the service. I don't know if the PHP SoapClient dynamically creates the proxy from the WSDL but if the WSDL generated by ASMX vs WCF is significantly different then that may cause the initial bottleneck.
我们的问题已通过修复 php.ini 中
soap.wsdl_cache_dir
的位置得到解决。我们的网站是在 Windows 计算机上托管和开发的,因此默认目录“/tmp”不起作用。将其更改为 C:\Windows\Temp 意味着虽然初始连接仍然很慢,但所有后续请求都很快。
我们现在将研究使用更常见的预热脚本解决方案。
Our problem has been resolved by fixing the location of
soap.wsdl_cache_dir
in php.ini.Our websites were hosted and developed on Windows machines, so the default directory of '/tmp' didn't work. Changing this to C:\Windows\Temp has meant although the initial connection is still slow, all subsequent requests are fast.
We will now look into using a more common solution of a warm-up script.