Windows实战:探寻IIS最大并发数
创始人
2024-06-12 18:01:44
0

测试系统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);
}
}
}

/**
* author : yurow
* http://birdshover.cnblogs.com
* description:
*
* history : created by yurow 2009-8-16 0:29:05
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace MaxLinked {
///


///
///

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连接数实验——Web开发必读 》),按两个计算,那么IIS默认情况下,最大并发数是4000个左右。

打开应用程序池配置,把最大工作进程数调高(默认为1),能有效提高最大连接数。我记得以前看过一篇文章,讲的是调到5左右比较合适。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...