我正在尝试模拟300,000个消费者访问服务器的情景。因此,我正在通过从并发线程中重复查询服务器来创建伪客户端。
但首先要克服的障碍是,在PC上是否可能运行300,000个线程?这里有一段代码,我正在使用它来查看最初可以获得多少最大线程,然后再用实际函数替换测试函数:
但首先要克服的障碍是,在PC上是否可能运行300,000个线程?这里有一段代码,我正在使用它来查看最初可以获得多少最大线程,然后再用实际函数替换测试函数:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace CheckThread
{
class Program
{
static int count;
public static void TestThread(int i)
{
while (true)
{
Console.Write("\rThread Executing : {0}", i);
Thread.Sleep(500);
}
}
static void Main(string[] args)
{
count = 0;
int limit = 0;
if (args.Length != 1)
{
Console.WriteLine("Usage CheckThread <number of threads>");
return;
}
else
{
limit = Convert.ToInt32(args[0]);
}
Console.WriteLine();
while (count < limit)
{
ThreadStart newThread = new ThreadStart(delegate { TestThread(count); });
Thread mythread = new Thread(newThread);
mythread.Start();
Console.WriteLine("Thread # {0}", count++);
}
while (true)
{
Thread.Sleep(30*1000);
}
} // end of main
} // end of CheckThread class
} // end of namespace
现在我尝试的可能有些不切实际,但是如果有解决方法并且您知道,请帮助我。