클라이언트 서버 응용 프로그램을 테스트해야합니다. 일부 포트에서 실행되는 서버가 있고 서버를 연결하는 약 2,000 개의 클라이언트를 만들어야합니다. 이를 위해 나는스레드 생성 중 시스템이 메모리가 부족합니다.
class Program
{
/// <summary>
/// Sample client code that makes gRPC calls to the server.
/// </summary>
public static void Main(string[] args)
{
for (int i = 0; i <= 2000; i++)
{
CalThread cThread = new CalThread(i);
} // Exception Raised Here
}
}
class CalThread
{
public CalThread(int clientID)
{
Thread thread = new Thread(() => getDataFromServer(clientID));
thread.Start();
}
public void getDataFromServer(int clientID)
{
try
{
//Channel channel = new Channel("192.168.0.123:50051", ChannelCredentials.Insecure);
while (true)
{
//Some code to connect to server and fetch data
Thread.Sleep(15000);
}
}
catch (Exception ex)
{
Thread.Sleep(15000);
Console.WriteLine(ex.Message);
}
}
}
여기에 예외이 예외를 발생 만 110 MB
메모리를 소비하지만 내가 확인했다 for loop of Main method
에서 응용 프로그램을 System.OutOfmemory
발생 다음 코드를 사용하여 C# 응용 프로그램 2000 개 스레드를 만들려고하고 있어요?
왜 C#은 숫자로 스레드를 만들지 못하게합니까? 나는 또한 Thread Pool
을 시도했지만 작동하지 않습니다 ...
'ThreadPool'을 사용하면 할 수 있습니다. –