WCF 限制请求 [英] WCF throttles requests

查看:28
本文介绍了WCF 限制请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要维护一个用 WCF 编写的旧服务.问题是在对服务进行负载测试时,请求似乎受到了限制.平均每个调用在服务器端花费大约 250 毫秒.如果我发送一个请求,它会在 250 毫秒多一点的时间内完成.如果我发送 10 个请求,前几个请求立即完成,其他请求在几秒钟内完成,其中秒数随着请求数的增加而增加.

I need to maintain an older service that's written in WCF. The issue is that when load testing the service, the requests appear to be throttled. On average each call takes around 250 ms on the server side. If I send one request, it completes in a little over 250 ms. If I send 10 requests, the first few complete right away and other requests are complete in seconds, where the number of seconds increases with the number of requests.

我在这里的一个简单项目中重现了这个问题 https://github.com/popsovy/TestWcfService

I reproduced the issue in a simple project here https://github.com/popsovy/TestWcfService

服务在 Service1.svc.cs 中休眠 250 毫秒:

The service sleeps for 250 ms in Service1.svc.cs:

    async public Task<string> ExecuteMethod()
    {
        await Task.Delay(250);
        return "Done";
    }

而且,客户端创建了 100 个调用该方法的线程.这些调用似乎不是并行执行的.所有线程同时开始,但有些线程在 20 秒以上完成.

And, the client creates 100 threads calling for that method. The calls appear to be NOT executing in parallel. All threads start at the same time but some of the threads finish in more than 20 seconds.

有趣的是,我使用此处提供的 WebApi 创建了一个类似的项目 https://github.com/popsovy/TestWebApi,并且行为是我所期望的——所有 100 个线程几乎立即启动,所有线程在大约 260 毫秒内完成——预期行为.

Interestingly, I created a similar project using WebApi available here https://github.com/popsovy/TestWebApi, and the behavior is what I would expect -- all 100 threads fire up almost immediately and ALL of the threads complete in about 260 ms -- the expected behavior.

WCF 服务似乎被限制或阻止执行许多并发请求.有没有办法让 WCF 版本表现得像 WebApi 版本一样——同时处理所有请求?

It appears that the WCF service is throttled or held back from executing many concurrent requests. Is there a way to make WCF version to behave like the WebApi version -- to process all the requests at the same time?

谢谢.

推荐答案

这是一个客户端问题 -- 在对服务执行多线程调用之前,我必须调用 client.Open().

This was a client side issue -- I had to call client.Open() before executing multi-threaded calls to the service.

这篇关于WCF 限制请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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