我正在使用以下代码尝试测试如果我增加并发连接数(即ClientCount应用程序配置值),网络消耗(从任务管理器的网络选项卡监视)是否会增加。但我发现即使我将客户端数量从100增加到500,网络消耗仍然是相同的(从客户端和服务器端大约3%-4%)。有什么想法有什么不对?我想证明客户端的并发数量是否增加,客户端和服务器网络消耗都会增加。
这是我的应用程序配置和客户端代码。 URL是在本地LAN中的另一台计算机上的IIS 7.0比特率限制控制中托管的wmv文件。我正在使用VSTS 2008 + C#+ .Net 3.5来开发控制台应用程序作为客户端。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="1000000" />
</connectionManagement>
</system.net>
<appSettings>
<add key="URL" value="http://labtest2/test.wmv"/>
<add key="ClientCount" value="100"/>
<add key="Timeout" value="3600"/>
</appSettings>
</configuration>
class Program
{
private static int ClientCount = 100;
private static string TargetURL = String.Empty;
private static int Timeout = 200;
static void PerformanceWorker()
{
Stream dataStream = null;
HttpWebRequest request = null;
HttpWebResponse response = null;
StreamReader reader = null;
try
{
request = (HttpWebRequest)WebRequest.Create(TargetURL);
request.Timeout = Timeout * 1000;
request.Proxy = null;
response = (HttpWebResponse)request.GetResponse();
dataStream = response.GetResponseStream();
reader = new StreamReader(dataStream);
// 1 M at one time
char[] c = new char[1000 * 1000];
while (reader.Read(c, 0, c.Length) > 0)
{
Console.WriteLine(Thread.CurrentThread.ManagedThreadId + ":\t" + c[0]);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
finally
{
if (null != reader)
{
reader.Close();
}
if (null != dataStream)
{
dataStream.Close();
}
if (null != response)
{
response.Close();
}
}
}
static void Main(string[] args)
{
TargetURL = ConfigurationSettings.AppSettings["URL"];
ClientCount = Int32.Parse(ConfigurationSettings.AppSettings["ClientCount"]);
Timeout = Int32.Parse(ConfigurationSettings.AppSettings["Timeout"]);
Thread[] workers = new Thread[ClientCount];
for (int i = 0; i < ClientCount; i++)
{
workers[i] = new Thread((new ThreadStart(PerformanceWorker)));
}
for (int i = 0; i < ClientCount; i++)
{
workers[i].Start();
}
for (int i = 0; i < ClientCount; i++)
{
workers[i].Join();
}
return;
}
}
答案 0 :(得分:1)
也许服务器上有最大并发呼叫限制,你能查一下吗?有些服务器例如10个并行连接(实际上它们也可以是单线程,只有1个并发呼叫)。