当前位置: 首页 > 图文教程 > 服务器 > Windows服务器 > 你的服务器IIS最大并发数有多少?

Windows服务器
自动实现Windows 2000系统补丁的快速安装
快速恢复Windows 2000/XP遗忘的管理员密码
Windows 2000/XP操作系统中超强命令syskey
环境变量应用:多系统共享程序
如何配置windows 2003的DNS服务器
Win 2003远程管理的实现
Win 2003轻松识别外来设备
Win 2003实现网络共享还原
体验Win 2003共享“还原”技术
用Windows 2003实现网络共享还原
激活windows 2003常用服务
windows 2003常见故障诊断
轻松提高windows 2003的运行速度
windows 2003中IE安全区域的设置技巧
改变windows 2003登录方式
windows 2003中给用户文件指派登录脚本
在windows 2003创建映像之前使用Sysprep
怎样在windows 2003下使用USB便携存储器
NT升级至windows 2003如何应用注册表和文件系统
windows 2003中配置PPTP VPN客户端筛选器

Windows服务器 中的 你的服务器IIS最大并发数有多少?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-04   浏览: 40 ::
收藏到网摘: n/a

做完假设,现在做限制,设置站点保持HTTP连接,超时设置成0,就是不会超时。在站点请求的default.aspx页面设置线程Thread.Sleep(int.MaxValue),接下来开发一个用来保持连接的小程序。 测试系统Window 2003 Server ,IIS 6.0 ,ASP.Net 3.5 sp1
Dual 1.8双核,2G内存,14G虚拟内存。
为了探寻IIS的最大并发数,先要做几个假设。
1、假设最大并发数就是当前的连接数。意思是当前能承受最大的连接,那么就表明最大的并发。
2、假设IIS应用程序池处于默认状态,更改设置将会对最大连接数产生影响。
做完假设,现在做限制,设置站点保持HTTP连接,超时设置成0,就是不会超时。在站点请求的default.aspx页面设置线程Thread.Sleep(int.MaxValue),接下来开发一个用来保持连接的小程序。
复制代码 代码如下:

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("错误消息:{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("建立连接失败!");
}
}
public void Close() {
if (response != null)
response.Close();
request.Abort();
}
}
}

程序设置为只能启动1800个线程,这是由于.Net单进程最大线程数好像是2000个。因此,要测试最大并发数,要需要同时开几个测试进程。把系统虚拟内存调到最大值,线程过多会急剧占用内存。现在开始测试。
打开web站点的性能计数器,把显示比例调成1万。
发现到5000个连接时,IIS服务器崩溃(503错误),去洗了个澡,发现IIS服务器无法自己修复错误。又测试了几次,发现最大并发值是8200个,但是一般到5000左右就会崩溃,有时候甚至只有1000个。
按8200个计算,一个用户开一个浏览器浏览网页,可能会占用2~3个连接,按两个计算,那么IIS默认情况下,最大并发数是4000个左右。
打开应用程序池配置,把最大工作进程数调高(默认为1),能有效提高最大连接数。我记得以前看过一篇文章,讲的是调到5左右比较合适。