Test System Window 2003 Server, IIS 6.0, ASP.net 3.5 SP1
Dual 1.8 Dual Core, 2G memory, 14G virtual memory.
To explore the maximum number of concurrent IIS, make a few assumptions.
1. Assume that the maximum concurrent number is the current number of connections. This means that the maximum connection is currently available, and then the maximum concurrency is indicated.
2. Assuming that the IIS application pool is in the default state, the change setting will have an impact on the maximum number of connections.
Finish the assumption, now do the limit, set the site to keep the HTTP connection, timeout set to 0, is not timed out. Set the thread thread.sleep (int) on the Default.aspx page of the site request. MaxValue), then develop a small program to keep the connection.
Copy Code code as follows:
Class Program {
private volatile static int errorcount = 0;
private volatile static int rightcount = 0;
static void Main (string[] args) {
Servicepointmanager.defaultconnectionlimit = 10000;
int count = 0;
int all = 0;
while (true) {
all++; count++;
CreateThread ();
Thread.Sleep (10);
if (count >= 200) {
Console.WriteLine (String. Format ("Sucess:{0};error:{1}", All-errorcount, Errorcount));
Count = 0;
}
if (All > 1800)
Break
}
Console.readkey ();
}
static void CreateThread () {
Thread thread = new Thread (activerequest);
Thread. IsBackground = true;
Thread. Start ();
}
static void Activerequest () {
Requestclient client = new Requestclient ("http://192.168.18.2/default.aspx?d=" + guid.newguid ());
Client. Requestprocess ();
if (client. IsError) {
errorcount++;
Console.WriteLine (String. Format (Error message: {0}), client. Messages));
} else {
rightcount++;
Console.WriteLine (client. Messages);
}
}
}
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Net;
Using System.IO;
Namespace Maxlinked {
<summary>
///
</summary>
public class Requestclient {
HttpWebRequest request;
WebResponse response;
Public requestclient (string url) {
Request = (HttpWebRequest) httpwebrequest.create (URL);
Request. Timeout = Int. MaxValue;
Request. KeepAlive = true;
ErrorCode =-1;
}
public void AddHeader (string name, String value) {
Request. Headers.add (name, value);
}
private bool IsError = false;
Private StringBuilder buffer = new StringBuilder ();
public int ErrorCode {get; set;}
public bool IsError {
get {return isError;}
}
public string Messages {
get {return buffer. ToString (); }
}
public void requestprocess () {
try {
Response = Request. GetResponse ();
catch (WebException ex) {
ErrorCode = (int) ex. Status;
Buffer. Append (ex. message);
IsError = true;
}
if (response!= null) {
Stream stream = null;
StreamReader reader = null;
try {
Stream = Response. GetResponseStream ();
reader = new StreamReader (stream, Encoding.UTF8);
Buffer. Append (reader. ReadToEnd ());
catch (Exception ex) {
Buffer. Append (ex. message);
IsError = true;
finally {
if (reader!= null)
Reader. Close ();
if (stream!= null)
Stream. Close ();
}
} else {
IsError = true;
Buffer. Append ("Failed to establish connection!") ");
}
}
public void Close () {
if (response!= null)
Response. Close ();
Request. Abort ();
}
}
}
The program is set to start only 1800 threads, due to the. NET single process the maximum number of threads seems to be 2000. Therefore, to test the maximum concurrency number, you need to open several test processes at the same time. With the system virtual memory tuned to maximum, too many threads can consume memory dramatically. Start testing now.
Open the performance counters for your Web site and turn the zoom to 10,000.
When 5,000 connections were found, the IIS server crashed (503 error), took a shower and found that the IIS server could not fix the error on its own. and tested several times, found that the maximum concurrency value is 8,200, but generally to 5000 or so will crash, and sometimes even only 1000.
In 8,200 calculation, a user opens a browser browsing the Web page, may occupy 2~3 connection, in two calculation, then IIS by default, the maximum concurrency is about 4,000.
Open the application pool configuration to increase the maximum number of worker processes (default 1), which can effectively improve the maximum number of connections. I remember reading an article before, talking about the adjustment to 5 or so more appropriate.