{"id":150,"date":"2007-08-06T17:51:20","date_gmt":"2007-08-07T00:51:20","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/150"},"modified":"2007-08-06T17:51:20","modified_gmt":"2007-08-07T00:51:20","slug":"throttling-in-wcf","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=150","title":{"rendered":"Throttling in WCF"},"content":{"rendered":"<p>When your server is hosted out on the &#8220;big bad internet&#8221;, you need a way to make sure that you don&#8217;t get flooded with client requests. In WCF, our services support <strong>throttling<\/strong> as a way of mitigating potential DoS (denial of service) attacks. These throttles can also help you smooth load on your server and help enforce resource allocations. There are three service-level throttles that are controlled by <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.servicemodel.description.servicethrottlingbehavior.aspx\">ServiceThrottlingBehavior<\/a>. These are in addition to any transport-specific throttles imposed by your binding. To fully understand the impact of these throttles you should also understand the <a href=\"http:\/\/kennyw.com\/indigo\/178\">threading\/instancing characteristics<\/a> of your service.<\/p>\n<ol>\n<li><strong><em>MaxConcurrentCalls<\/em><\/strong> bounds the total number of simultaneous calls that we will process (default == 16). This is the only normalized throttle we have across all of the outstanding reads that the ServiceModel Dispatcher will perform on any channels it accepts. Each call corresponds to a Message received from the top of the server-side channel stack. If you set this high then you are saying that you have the resources to handle that many calls simultaneously.  In practice how many calls will come in also depends on your <a href=\"http:\/\/kennyw.com\/indigo\/178\">ConcurrencyMode and InstancingMode<\/a>.<\/li>\n<li><strong><em>MaxConcurrentSessions<\/em><\/strong> bounds the total number of sessionful channels that we will accept (default == 10). When we hit this throttle then new channels will not be accepted\/opened. Note that this throttle is effectively disabled for non-sessionful channels (such as default BasicHttpBinding).\n<p>With TCP and Pipes, we don\u2019t ack the preamble until channel.Open() time.  So if you see clients timing out waiting for a &#8220;preamble response&#8221;, then it&#8217;s possible that the target server has reached this throttle. By default your clients will wait a full minute (our default SendTimeout), and then time out with a busy server.  Your stack will look something like:<\/p>\n<blockquote><p>\nTestFailed System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.<br \/>\n[&#8230;]<br \/>\nat System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.<strong>SendPreamble<\/strong>(IConnection connection, ArraySegment`1 preamble, TimeoutHelper&#038; timeoutHelper)\n<\/p><\/blockquote>\n<p>If instead you are timing out under channel.Send (rather than channel.Open), then it&#8217;s possible that you are hitting the MaxConcurrentCalls throttle (which kicks in per-message, not per-channel).<\/p>\n<\/li>\n<li><strong><em>MaxConcurrentInstances<\/em><\/strong> bounds the total number of instances created. This throttle provides added protection in the case that you have an instance lifetime that is not tied to a call or a session (in which case it would already be bounded by the other two throttles). <a href=\"http:\/\/weblogs.asp.net\/gsusx\/archive\/2007\/06\/14\/orcas-durable-services.aspx\">Orcas durable services<\/a> are one such scenario.\n<\/li>\n<\/ol>\n<p>Net-net: if you are testing your services under load, and your clients start timing out, take a look at your throttling and instancing values. On the flip side, do not just blindly set these to int.MaxValue without fully understanding the potential DoS consequences.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When your server is hosted out on the &#8220;big bad internet&#8221;, you need a way to make sure that you don&#8217;t get flooded with client requests. In WCF, our services support throttling as a way of mitigating potential DoS (denial of service) attacks. These throttles can also help you smooth load on your server and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}