当前位置: 移动技术网 > 网络运营>服务器>Windows > 你的服务器IIS最大并发数有多少?

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

2019年04月20日  | 移动技术网网络运营  | 我要评论
测试系统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左右比较合适。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网