How do IIS understand or know my timeout duration? - c#

I have a asp.net web api where is host on IIS and I use restsharp for request operations. I also added a timeout for requests. So far everything is normal.
When i did a load test to my api, some requests queued on IIS, I saw these requests at worker process screen on IIS. How can i kill these processes automatically or how do IIS understand or know my timeout duration ? I have a timeout whereas it doesn' t work.
IRestClient _client = new RestClient(url) { Timeout = timeout};

Related

Cannot read request body in Owin (stuck in ReadAsStringAsync)

Running OWIN self-hosting web service in Azure Service Fabric behind Azure Load Balancer and Azure Traffic Manager Profile with multiple instances.
About 2% of web requests stuck when service is trying to read the request body from incoming requests to string using HttpContent.ReadAsStringAsync. So the ReadAsStringAsync fails after timeout :
System.Net.Http.HttpRequestException: Error while copying content to a stream.
Web service receives request with different sizes most of them are small but some could be up to 60K. The number of concurrent pending requests/instance is about 900 and CPU load ~30%.
Scaling out number of services helps a little bit but does not solve it completely, I am also trying to understand what is the root cause.
Here is the setting I override in OwinHttpListener:
listener.SetRequestProcessingLimits(Environment.ProcessorCount * 5, int.MaxValue);
listener.SetRequestQueueLimit(10000);
Any ideas of the root cause and/or how to fix it?
Owin ver:
PackageReference Include="Microsoft.AspNet.WebApi.Owin" Version="5.2.6"

504 Gateway timeout when using Azure Service Bus Relay to serve static files

I am serving static files (a web page) over a wcf azure relay, but one (or more) of the js files will return 504 gateway timeout, and the html page takes a while to load. However, there were no issues when serving the files directly through a port on the server. Will changing the ReceiveTimeout or SendTimeout on the Web​Http​Relay​Binding have any effect on this, or could it be something else related to the wcf configuration? If not, is there any other way to troubleshoot this problem?
I can post some more code if needed but the setup for the wcf connection is similar (but slightly different) to the wcf relay sample (https://github.com/Azure/azure-relay/blob/master/samples/WCF%20Relay/RelayHttpNoAuth/Service/Program.cs):
host.AddServiceEndpoint(
GetType(),
new WebHttpRelayBinding(
EndToEndWebHttpSecurityMode.None,
RelayClientAuthenticationType.None) {IsDynamic = true},
httpAddress)
.EndpointBehaviors.Add(
new TransportClientEndpointBehavior(
TokenProvider.CreateSharedAccessSignatureTokenProvider(listenToken)));
host.Open();
Edit:
This ended up being the cause of why the requests were timing out. It really wasn't directly related to Azure Service Bus at all.

wcf service long httpwebrequest wait causes queuing of subsequent requests

I have a WCF service that in functionA makes an HttpWebRequest call to functionX in an external service. Originally the timeout on this httpwebrequest was set to 5 minutes.
Recently, the external service has been taking longer than 5 minutes to respond (which I am ok with). So I bumped the httpWebRequest.timeout up to 10 minutes.
Meanwhile the wcf service should be able to process other incoming requests (to functionB, functionC, etc). What I'm experiencing now is that if functionX takes longer than ~5 minutes to respond (and thus functionA takes longer than 5 minutes to complete), subsequent requests to functionB in my wcf service are queued / do not process until functionA completes.
In the end everything completes properly, but I don't see why functionB is affected by the waiting that is happening over in functionA.
Forgive me if that is hard to follow. It is a strange and I'm having trouble wrapping my head around how these pieces are related.
You must decorate your WCF Service class with following attribute
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] // The service instance is multi-threaded.
public class Service1
{
// ...
}
I assume your concurrency mode is set to Single defined as follows by Microsoft.
"The service instance is single-threaded and does not accept reentrant calls.
If the System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode property is System.ServiceModel.InstanceContextMode.Single, and additional messages arrive while the instance services a call, these messages must wait until the service is available or until the messages time out."
i had a same problem. i hosted my service in IIS. after little search i found out its because of maxconnection limit in web config. i added this line in to my web.config and the problem solved:
<system.net>
<connectionManagement>
<add address="*" maxconnection="1000"/>
</connectionManagement>
</system.net>
by default maxconnection value is 2.
but this is one of the many reasons. you should monitor your server requests in order to find out the exact reason.

Web service concurrent calls processing

I've faced with the next issue related to web service request processing:
Preamble
I have
Web api service hosted on IIS 7.0 on local machine
Test harness console application on the same machine
and i'm trying to simulate web service load by hitting one with requests generated via test harness app.
Test harness core code:
static int HitsCount = 40;
static async void PerformHitting()
{
{
await Task.WhenAll(ParallelEnumerable.Range(0, HitsCount)
.Select(_ => HitAsync())
.WithDegreeOfParallelism(HitsCount));
}
}
static async Task HitAsync()
{
// some logging skipped here
...
await new HttpClient().GetAsync(TargetUrl, HttpCompletionOption.ResponseHeadersRead);
}
Expectation
Logging shows that all HitAsync() calls are made simultaneously: each hit via HttpClients had started in
[0s; 0.1s] time frame (timings are roughly rounded here and below). Hence, I'm expecting to catch all these requests in approximately the same time frame on web service side.
Reality
But logging on the service side shows that requests grouped in bunches 8-12 request each and service catches these bunches with ~1 second interval. I mean:
[0s, 0.3s] <- requests #0-#10
[1.2s, 1.6s] <- requests #10-#20
...
[4.1s, 4.5s] <- request #30-#40
And i'm getting really long execution time for any significant HitCount values.
Question
I suspect some kind of built-in service throttling mechanism or framework built-in concurrent connections limitation. Only I found related to such guesstimate is that, but i didn't get any success trying soulutions from there.
Any ideas what is the issue?
Thanks.
By default, HTTP requests on ASP.NET are limited to 12 times the number of cores. I recommend setting ServicePointManager.DefaultConnectionLimit to int.MaxValue.
Well, the root of the problems lies in the IIS + Windows 7 concurrent requests handling limit (some info about such limits here. Moving service out to the machine with Windows Server kicked out the problem.

Increasing timeout of ASMX webservices

I am running an ASMX webservice on IIS 7. The client is a silverlight application. I am issuing several asynchronous file requests to the webservice and processing them on AsyncCompleted. Sometime after all the async requests have been issued, I get the following timeout message. How can the timeout be increased.
I tried adding the following in the web.config of the ASP.NET project that is hosting my silverlight application.
<httpRuntime executionTimeout="12000"/>
(This timeout is not happening when I do the requests synchronously, but synchronous operations are very slow.)
The HTTP request to 'http://localhost:5080/Service1.asmx' has exceeded the
allotted timeout.
See these sources:
Timeout error in WCF
Silverlight Timeout Issues from WCF… exceeded the allotted timeout.
Because this is the silverlight application i am in a doubt if my suggestion will work.
Just try, to create the object of the webservice and then increase the time out value to what ever seconds you want.
Below code may be helpful
ConsoleApplicationFor2Groups.AdServices.ADService adser = new ADService();
adser.Timeout = 100000; // this time is in milliseconds
Just let me know if this works.

Categories