Example #1
0
        public LoadGenerator(
            int threadCount,
            TimeSpan duration,
            Uri uri,
            int numOfMeasuredThreads,
            int metricsCollectionCapacity)
        {
            _duration        = duration;
            _tcpWorkerHelper = new TcpWorkerHelper(uri);

            _signals = Enumerable.Range(0, threadCount).Select(i => new ManualResetEvent(false)).ToList();
            _threads = Enumerable.Range(0, threadCount).Select(i =>
            {
                var method = i < numOfMeasuredThreads ?
                             new ParameterizedThreadStart(Work_WithMetrics)
                    : new ParameterizedThreadStart(Work_WithoutMetrics);

                return(new Thread(method)
                {
                    IsBackground = true
                });
            }).ToList();

            var maxMeasuredThread = _threads.Count < numOfMeasuredThreads?
                                    _threads.Last()
                                        : _threads[numOfMeasuredThreads - 1];

            _metrics = new GlobalMetrics(
                _threads.Max(t => t.ManagedThreadId),
                maxMeasuredThread.ManagedThreadId,
                new SysPerfLogger(duration),
                metricsCollectionCapacity);
        }
Example #2
0
 public TcpWorker(TcpWorkerHelper helper)
 {
     _helper = helper;
     _client = new TcpClient()
     {
         ReceiveTimeout = 10000, NoDelay = true
     };
     _responseBuffer = new byte[_client.ReceiveBufferSize];
 }