如何提高WCF服务调用的速度?一世 [英] How to increase the speed of a WCF service call? I

查看:117
本文介绍了如何提高WCF服务调用的速度?一世的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wcf服务调用来调用一个方法来填充数据网格。这需要很长时间才能从服务运营合同中检索列表。有时当我关闭我的防病毒软件时,执行时间会快一些。这与我的防病毒有什么关系吗?如何提高服务调用速度?

* IMP *同样的事情已经在没有wcf操作合同的情况下进行了测试,与wcf服务合同相比,执行速度更快更快。



我尝试了什么:



试图增加超时,分页但没有后果。

I am using a wcf service call to call a method to populate a datagrid. This is taking long time to retrieve the list from the service operation contract. and sometimes when i turn off my antivirus the execution time is a little faster. Does this have anything to do with my antivirus. How can i increase the service call speed?
*IMP* the same thing has been already tested without wcf operation contract the execution is much more faster and quicker compared to wcf service contract.

What I have tried:

Tried to increase timeout,paging but with of no consequences.

推荐答案

嗨Yogi @ FLG,



你没有提到你如何调用你的WCF服务从你的申请(?)。如果你真的想知道性能,你必须在生产附近的环境中进行测试。你提到你的防病毒软件 - 这并不是你理解性能测试的好兆头(你更有可能使用一些网络检测工具,而不仅仅是防病毒软件)。忘了这一点,只使用编译和运行(JITTED)代码进行生产附近或最低要求系统的性能比较 - 而不是得出你的结论。

更不用说直接调用永远是合乎逻辑的比通过服务电话更快(你明白这是如何工作的?),但这是主题的本质 - 你创建服务来制作技术独立,可重复使用的部分,而不是为了性能!



您没有提到您的具体情景,因此很难给出好的建议。

但是对于WCF,我可能会考虑一些事情。

*消息/数据协议/序列化 - SOAP / JASON(你的对象图有多深? )您是否考虑到这一点设计了您的服务方法(我尝试使用最少的信息传递。例如,如果我需要客户的订单,我们发送整个客户对象,如果您只需要客户ID来选择来自您的数据存储区的订单)。

*尝试模拟不同的网络延迟。

*如果数据需求非常高且您无能为力 - 可能会考虑不同的模式(数据分页,缓存或后台同步) - 例如在当前项目中,我在客户端使用数据虚拟化,最初只加载3页数据。)

*取决于你如何调用你的wcf服务(throgh代理?)但如果你按需创建channelfactory和渠道:最好是存储您在缓存中调用的每个合约的channelfactories(简单字典会这样做) - 因此在应用程序中只创建一次,然后根据需要从缓存的channelfactories创建/删除新频道(创建工厂是昂贵的任务,从缓存的工厂创建频道是闪电般快速的)



如果你告诉我你使用什么绑定,也许我可以提供一些进一步的建议以及如何从客户端调用服务(虽然可能是anothter服务)。托管环境,实例 - 上下文模式等其他信息也会对你应该知道的性能产生一点影响 - 正如我所说的那样 - 在机器开发期间永远不会进行性能测试 - 总是使用参考系统(通常你会使调试变得容易在开发过程中,您将在运行客户端代码的同一台计算机上托管服务,因此如果性能至关重要,则必须使用真正的网络延迟进行真正的性能测试。



在提到所有这些之后,我不得不说在我用wcf服务架构做了很多项目之后,我更想知道为什么一切都比为什么这么快慢。最后,服务是一种抽象,你总是要为此付出代价,但真正糟糕的表现(与直接电话相比)暗示可能是某种错误 - 并且避免了愚蠢的反病毒 - 套件(像forticlient或其他东西)可能会产生负面影响 - 但我只考虑生产环境迫使我这样做....(然后为工具创建例外或规则)



我希望我的一些想法可以帮到你..快乐的编码



亲切的问候Johannes
Hi Yogi@FLG,

You didn't mention how you call your WCF Service from your application(?). If you really want to know about performance you have to test it on a production-near nnvironment. You are mentioning your antivirus - that's not a good sign about your understanding of perfomance tests (more likely you use some network inspection tool, not antivirus alone). Forget about this, only use compiled and run (JITTED) code for perfomance comparison on production near, or minimum requirement system - than draw your conclusions.
Not to mention that it's logical that a direct call will always be faster than going through a service call (you understand how this works?), but that's by nature of the topic - you create Services to make tech independend, reusable parts, not for perfomance!

You didn't mention your specific Scenario, so it's quite hard to give good advice.
But for WCF some things come to my mind you may want to consider.
* Message/data protocol/serialization - SOAP/JASON (how deep are your object Graphs?) Did you design your Service methods with this in mind (I try to use the least Information passing possible. E.g if I Need the order's for a customer, wyh send the whole customer object, if you only need the customer-id to select the orders from your datastore).
* Try to simulate different network latencies.
* If data-need is very high and you can do nothing about it - maybe consider different patterns (data-paging, Caching or Background sync) - e.g. In a current project I use data-virtualization on the Client-side which will initially load only 3 pages of the data.)
* Depends how you call your wcf Service (throgh Proxy?) but if you create channelfactory and channels on demand: Best is to store the channelfactories for each contract you call in a cache (simple dictionary will do) - so create them only once in your application, then create/drop new channels as you need from your cached channelfactories (creating the factory is the expensive Task, creating channels from a cached factory is lightning fast)

Maybe I can give some further advice if you tell me what binding's you use and how you call the Service from the "client-side" (maybe anothter Service though). Other Information like hosting Environment, Instance-Context mode etc. also have a little influence on perfomace you should know about - as I said - make perfomance tests never during develpment on your machine - always use a reference system (normally you will make Debugging easy and during development you will host the services on the same computer where the client-Code is run), so real perfomance-test with real network-delay is a must if perfomance is critical.

After mentioning that all, I have to say after I have done many projects with wcf service-architecture, I wonder more often why all is so fast than why it's "slow". In the end a Service is an abstraction, and you always have to pay a price for that, but real bad perfomance (compared to a direct call) is a hint that maybe something is "wrong" - and shure a "stupid" antivirus-Suite (like forticlient or something) can have a negative Impact - but I'd only consider this if production environment forces me to do so.... (then create exceptions or rules for the tool whatever)

I hope some of my thoughts will help you.. Happy coding

Kind regards Johannes


这篇关于如何提高WCF服务调用的速度?一世的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆