如何提高WCF服务功能的性能 [英] How to improve performance of WCF Service Function

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

问题描述

我写了一个商店程序,它返回了23000条记录,并且收到了00:00:01秒。在Sql-Server中进行计时,但是当我使用WCF +实体框架调用此存储过程时,其要求时间为10秒(在本地网络中)以从数据库获取结果



那么如何减少WCF服务功能处理时间......

I have write a one store procedure it return 23000 records and its getting 00:00:01 Sec. Timing in Sql-Server ,but when i call this store procedure using WCF + Entity Framework its require timing is 10 Sec (in local Network) for getting result from database

So how to decrease WCF Service Function Processing Timing......

推荐答案

数据库服务器(SQL Server)是一个独立的应用程序,不需要除了一些因素(如延迟率等)之外,它还依靠任何东西为您提供数据。因此,执行命令(SELECT)只需1秒钟。



而另一方面,WCF必须依赖多种因素,例如网络。用户发出请求,服务器处理它,当代码想要连接到另一台服务器(例如SQL Server)时,请求被转移到该页面,SQL Server执行命令返回数据。 WCF服务器继续使用该数据并为您提供其他详细信息。



上面的过程需要花费很多时间,很多CPU周期,堆内存和许多其他东西。这就是为什么SQL Server本身耗时1秒的过程现在增加到10秒。你不能做任何事情来防止这种情况发生。但是可以有一个提示,为您解决问题。



1. 高效代码

代码效率越高,执行代码所需的时间越少。有很多因素导致CPU在一个没用的过程中浪费它的周期。变量初始化,字符串连接,值更新等过多。这些因素会导致您的机器性能降低。



2. 增加机器规格

如前所述,当CPU浪费时,应用程序和框架的执行效率会降低它的周期一无所获。要克服,您可以升级您的机器; CPU周期频率(Hz),RAM大小(GB)和其他类似的东西。如果您的服务托管在一台单独的机器上,那么网络带宽大小等等。



但是,毕竟。我建议1.有效的代码方法来克服这个问题。因为第二个选项会消耗更多资源,但仍然无法解决问题。编写高效的代码可以免费解决问题;都使用你的逻辑和常识。
Database server (SQL Server) is a stand-alone application that doesn't have to rely on anything to provide you with data, apart from a few factors such as latency rate etc. So that is why, executing the command (SELECT) would take only 1 second.

Whereas WCF on other hand has to depend on multiple factors, networking for example. User makes request, server handles it, when code wants to connect to another server (SQL Server for instance), the request is then transferred to that page, SQL Server executes command returns the data. WCF server continues to use that data and provide you with other details.

The above process does take a lot of time, a lot of CPU cycles, heap memory and many other things. That is why the process that SQL Server itself took 1 second, is now increased to 10 seconds. You cannot do anything to prevent this from happening. But there can be a tip, for you to solve the problem.

1. Efficient code
The more efficient your code, less time it takes to execute it. There are a lot of factors that cause the CPU to waste its cycles in a process that is of no use. Too many variable initialization, string concatenation, value updating and so on. These factors cause your machine to perform less efficiently.

2. Increase machine specifications
As already said, applications and frameworks perform less efficiently when CPU is wasting its cycles for nothing. To overcome, you can upgrade your machine; CPU cycle frequency (Hz), RAM size (GB) and other similar things. If your service is hosted on a separate machine, then the network bandwidth size and so on.

But, after all. I would suggest 1. Efficient code way of overcoming this problem. Because second option would consume more resources, but still won't fix the problem. Writing efficient code would solve the problem at no cost; all using your logic and common sense.


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

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