C # 응용 프로그램에서 300,000 개의 스레드를 만들어 PC에서 실행할 수 있습니까?

나는 30 만 명의 소비자가 서버에 액세스하는 시나리오를 모방하려고합니다. 따라서 동시 스레드에서 서버를 반복적으로 쿼리하여 의사 클라이언트를 만들려고합니다.

하지만 해결해야 할 첫 번째 장애물은 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

이제 내가 시도하는 것은 비현실적 일 수 있지만 여전히 방법을 알아 내면 제발 도와주세요.

7
задан Vadim Kotov 26 June 2018 в 12:32
поделиться