首页 > 开发 > IIS > 正文

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

2020-07-28 16:01:33
字体:
来源:转载
供稿:网友
做完假设,现在做限制,设置站点保持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());
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表