我试图模仿一个场景,其中有30万消费者正在访问服务器。所以我试图通过从并发线程反复查询服务器来创建伪客户端。我们可以在C#应用程序中创建300,000个线程并在PC上运行它吗?
但是要清除的第一个障碍是,是否可以在PC上运行300,000个线程?下面是我使用的,看我intially多少最大线程数可以得到的,后来再与实际的函数替换测试功能代码:
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
现在我想做可能是不现实的,但尽管如此,如果有办法做到这一点,你知道,那么请帮助我。
貌似http://stackoverflow.com/questions/145312/maximum-number-of-threads-in-a-net-app – holtavolt 2011-06-07 14:18:01
的副本如果 “跑” 你意味着线程之间的颠簸...... hehe – 2011-06-07 14:19:13
我很抱歉,我没有澄清目的太好。我的设置是服务器 - 客户端设置。我想强调客户端而不是服务器。在设置中,进程向客户端进程发出请求,客户端进程将依次将请求转发给要服务的服务器。 但我明白了我们都在接受的观点,即在一台机器上创建这些多线程是不现实的,不推荐使用。 此外,我打算让这些线程每1分钟至少执行一次,从而给客户端造成压力的动机似乎是太想要了! :( – 2011-06-07 17:30:33