C# WCF 服务限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/480020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Service Throttling
提问by Spence
Lets assume that I'm dealing with a service that involves sending large amounts of data.
让我们假设我正在处理一项涉及发送大量数据的服务。
If I implement this with WCF, will WCF throttle the service based on how much memory each request takes to serve? Or will I be getting continuous out of memory exceptions each time I receive a large number of hits to my service?
如果我用 WCF 实现这一点,WCF 会根据每个请求需要多少内存来限制服务吗?或者,每次我的服务收到大量点击时,都会出现连续的内存不足异常吗?
I'm quite curious as to dealing with this problem outside of WCF, I'm still a bit new to service development...
我很好奇在 WCF 之外处理这个问题,我对服务开发还是有点陌生......
采纳答案by EnocNRoll - AnandaGopal Pardue
While using the binding attributes and readerQuotas like Andrew Hare suggests will allow for essentially an unlimited size for most practical uses, keep in mind that the you will run into other issues such as timeouts if you accept a long running command, no matter how that service is constructed (using WCF or not).
虽然像 Andrew Hare 建议的那样使用 binding 属性和 readerQuotas 将允许在大多数实际用途中基本上不受限制,但请记住,如果您接受长时间运行的命令,您将遇到其他问题,例如超时,无论该服务如何构造(使用或不使用 WCF)。
No matter what the size of your message is, the WCF service will need to be throttled for performance so that it is not flooded. If you are hosting it in IIS or WAS, you will have additional built-in features to those hosting environments that will make your service much more "highly available". However, you still need to pay attention to concurrency issues. The following WCF config provides an example of setting some throttling values.
无论您的消息有多大,都需要对 WCF 服务进行节流以提高性能,以免被淹没。如果您在 IIS 或 WAS 中托管它,那么您将拥有额外的内置功能,这些功能将使您的服务更加“高度可用”。但是,您仍然需要注意并发问题。以下 WCF 配置提供了设置一些限制值的示例。
<system.serviceModel>
...
<behaviors>
<serviceBehaviors>
<behavior name="GenericServiceBehavior">
<serviceTimeouts transactionTimeout="00:09:10"/>
<serviceThrottling
maxConcurrentCalls="20"
maxConcurrentSessions="20"
maxConcurrentInstances="20"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
回答by Andrew Hare
WCF does have a default payload size limit that will reject messages over a certain number of bytes. This is configurable of course in the binding section of your configuration file. Here is a crude example with a basicHttpBinding
showing you many of the attributes available to you:
WCF 确实有一个默认的有效负载大小限制,它将拒绝超过特定字节数的消息。这当然可以在配置文件的绑定部分进行配置。这是一个粗略的示例,basicHttpBinding
向您展示了许多可用的属性:
<bindings>
<basicHttpBinding>
<binding name="testBinding" maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
The idea is that you can create many different bindings that you can use for different scenarios. This is nice as you can fine tune how your services are consumed and only increase the message size limit for the endpoints that need them.
这个想法是您可以创建许多不同的绑定,您可以将它们用于不同的场景。这很好,因为您可以微调服务的使用方式,并且只增加需要它们的端点的消息大小限制。
回答by Tad Donaghe
If you're using NetTCPBinding or NetNamedPipeBinding you can use the MaxConnections property:
如果您使用 NetTCPBinding 或 NetNamedPipeBinding,您可以使用 MaxConnections 属性:
<bindings>
<netTcpBinding>
<binding name="myTCPBinding" maxConnections="15"/>
</netTcpBinding>
</bindings>