Reputation: 566
Faced with the following problem at the same time sending 100 requests the server starts to slow down the adoption of a new query, the first 100 requests trigger a function that is performed for 1 minute and wait for the end of execution, 101 request I send a short call from the browser function that prints string and number of how many requests still running in parallel.
So after all the 100 requests and began working in the stream, the 101 function is quick and shows that 100 threads now running in parallel.
watched a lot of information on the Internet, everything seems as it should do but still no result
using NF 4.5
class attributes are set to work in parallel C # code
[CallbackBehavior(UseSynchronizationContext = false)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = 2147483646)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract(SessionMode = SessionMode.NotAllowed)]
function emulation load for 1 minute C # code
private static int threads11 = 0;
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
public string loadConcurency()
{
threads11++;
var count = 0;
while (count < 6000)
{
count++;
Thread.Sleep(10);
}
threads11--;
return "1";
}
function test statistic C # code
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
public string ReportTest()
{
try
{
StringBuilder response = new StringBuilder().AppendLine("threads=" + threads11.ToString() + "; ");
response.AppendLine();
return response.ToString();
}
catch (Exception ex)
{
return ex.ToString() + (ex.InnerException == null ? "" : ex.InnerException.ToString());
}
}
serviceThrottling set very high
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="3000" maxConcurrentSessions="30000" maxConcurrentInstances="3000" />
</behavior>
I hope those who met with such problem and will prompt what the problem, or at least give advice where else to dig
Upvotes: 2
Views: 857
Reputation: 566
Sorry automatic translation.
I did not consider another factor is a pool of input and output streams The default minimum pool is the number of cores CPU cycles, such as I, he was equal to 4 maximum value was 1023, but why then had problems when I was trying to make 100 threads??
the answer is that when we go beyond the minimum threshold, the server does not immediately allocate a new thread, and waits for about 0.5 seconds that freed one of the employees, and only then if still not found a free allocates a new thread .. Now taking into account that I do 100 connections you need to keep, the first 4 are taken to process instantly, the other 96 took approximately 96 seconds * 0.5 = 48 seconds, that is my next 101 test call waiting 48 seconds!
solution:
ThreadPool.SetMinThreads (4, 100);
I am sure that my answer and my work will be useful to someone, and do not give a lot of time to kill :)
Sources:
http://msdn.microsoft.com/ru-ru/library/system.threading.threadpool.setminthreads.aspx
WCF performance, latency and scalability
Upvotes: 2