简体   繁体   English

2 WCF服务和c#线程

[英]2 WCF Services and c# threading

I am trying to write code that imports a bunch of data as quickly and reliably as possible. 我正在尝试编写代码,以尽可能快而可靠地导入大量数据。 Using threading I have been able to speed up the import code I wrote significantly on my local machine, but when I run it on our remote server it seems to have some WCF problems... 使用线程,我能够加快我在本地计算机上编写的导入代码的速度,但是当我在远程服务器上运行它时,似乎出现了一些WCF问题...

I have two WCF Service implementations: Service1 and Service2. 我有两个WCF服务实现:Service1和Service2。

Basically this is the workflow: 基本上,这是工作流程:

Parallel.ForEach(objectData.Tables[0].Rows.Cast<DataRow>(), dataRow =>
{
...
    Service1.ImportObjectFirstPart(ObjectToEnter);
...
    Service2.ImportObjectSecondPart(ObjectToEnter);
}

Service1 call takes about 3 seconds, and service2 takes about 7 seconds both remotely and locally. 远程和本地调用Service1大约需要3秒,而service2大约需要7秒。 However on my local machine, calls to service2 start after about 20 service1 calls. 但是,在我的本地计算机上,对service2的调用在大约20个service1调用之后开始。 On the server, almost every service1 call finished before the first service2 call started. 在服务器上,几乎每个service1调用都在第一个service2调用开始之前完成。 (Both services are implemented as PerCall). (这两个服务都实现为PerCall)。

The code to call the services uses 99% CPU as expected for awhile then slows to a crawl, then I have to exit it myself. 调用服务的代码会在一段时间内按预期使用99%的CPU,然后减慢爬网速度,然后我必须自己退出。 Any idea what could be going wrong? 任何想法可能出什么问题吗?

Thanks, 谢谢,

Have you tried 你有没有尝试过

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

you can read the details here 您可以在这里阅读详细信息

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx

The default is single so you should expect the behavior you are getting is pretty justified. 默认值为单一,因此您应该期望得到的行为是合理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM