掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流

在焦作等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站設計制作、網(wǎng)站設計 網(wǎng)站設計制作定制制作,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,成都品牌網(wǎng)站建設,成都營銷網(wǎng)站建設,外貿(mào)營銷網(wǎng)站建設,焦作網(wǎng)站建設費用合理。
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單進程最大線程數(shù)好像是2000個。因此,要測試最大并發(fā)數(shù),要需要同時開幾個測試進程。把系統(tǒng)虛擬內(nèi)存調(diào)到最大值,線程過多會急劇占用內(nèi)存?,F(xiàn)在開始測試。
打開web站點的性能計數(shù)器,把顯示比例調(diào)成1萬。
發(fā)現(xiàn)到5000個連接時,IIS服務器崩潰(503錯誤),去洗了個澡,發(fā)現(xiàn)IIS服務器無法自己修復錯誤。又測試了幾次,發(fā)現(xiàn)最大并發(fā)值是8200個,但是一般到5000左右就會崩潰,有時候甚至只有1000個。
按8200個計算,一個用戶開一個瀏覽器瀏覽網(wǎng)頁,可能會占用2~3個連接,按兩個計算,那么IIS默認情況下,最大并發(fā)數(shù)是4000個左右。
打開應用程序池配置,把最大工作進程數(shù)調(diào)高(默認為1),能有效提高最大連接數(shù)。我記得以前看過一篇文章,講的是調(diào)到5左右比較合適。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流