示例#1
0
        private static void InternalResponseHandlerTestSingleThread(SessionBase session)
        {
            NetTcpBinding binding = Utils.CreateNetTcpBinding();

            byte[] task_data = new byte[input_data_size];
            (new Random()).NextBytes(task_data);

            data.SendStart = DateTime.Now;

            var responseHandlers = new List <ResponseHandlerBase>();

            for (int i = 0; i < batchCount; i++)
            {
                int msg_count = req_count / batchCount;
                if (i == batchCount - 1)
                {
                    msg_count += req_count % batchCount;
                }

                string clientId = Environment.MachineName + "-" + i.ToString() + "-" + Process.GetCurrentProcess().Id.ToString();
                var    client   = new BrokerClient <IService1>(clientId, session, binding);

                ResponseHandlerBase handler;
                handler = new ComputeWithInputDataResponseHandler(client, clientId, common_data_size, retryRequestAndIgnoreRetryOperationError);
                client.SetResponseHandler <ComputeWithInputDataResponse>(((ComputeWithInputDataResponseHandler)handler).ResponseHandler <ComputeWithInputDataResponse>);
                responseHandlers.Add(handler);
                ClientSendRequest(client, clientId, msg_count, task_data);
            }
            //Log("The max interval of SendRequest opertaion is {0} milliseconds.", sendInterval);
            data.SendEnd = DateTime.Now;

            foreach (ResponseHandlerBase handler in responseHandlers)
            {
                handler.WaitOne();
                data.ResultCollection.AddRange(handler.results);
                data.FaultCount += handler.faultCalls;
                try
                {
                    handler.client.Close(durable, 10 * 60 * 1000);
                }
                catch (Exception e)
                {
                    Log("Purge client {0} failed: {1}", handler.clientId.ToString(), e.ToString());
                }
            }

            data.RetrieveEnd = DateTime.Now;
        }
示例#2
0
        private static void CustomizedResponseHandlerTest(SessionBase session)
        {
            NetTcpBinding binding = Utils.CreateNetTcpBinding();

            byte[] task_data = new byte[input_data_size];
            (new Random()).NextBytes(task_data);

            object mylock = default(object);

            for (int i = 0; i < req_count; i++)
            {
                string clientId = Guid.NewGuid().ToString();
                BrokerClient <IService1> client = new BrokerClient <IService1>(clientId, session, binding);
                ResponseHandlerBase      handler;
                handler = new ComputeWithInputDataResponseHandler(client, clientId, common_data_size, retryRequestAndIgnoreRetryOperationError);

                // Measure the set response handler time
                Stopwatch watch = Stopwatch.StartNew();
                client.SetResponseHandler <ComputeWithInputDataResponse>(
                    response =>
                {
                    lock (mylock)
                    {
                        response.Dispose();
                        client.Close();
                    }
                }
                    );
                watch.Stop();
                Log("Elapsed time for SetResponseHandler is {0} milliseconds", watch.ElapsedMilliseconds);

                // Send requests
                client.SendRequest <ComputeWithInputDataRequest>(new ComputeWithInputDataRequest(millisec_for_each_req, task_data, commonData_dataClientId, output_data_size, DateTime.Now));
                data.ReqEom = DateTime.Now;
                client.EndRequests(10 * 60 * 1000);
                data.ReqEomDone = DateTime.Now;

                // Send every 0-4 sec
                //Thread.Sleep((new Random()).Next(4000));
            }
        }
示例#3
0
        private static void InternalResponseHandlerTestMultiThreads(SessionBase session)
        {
            NetTcpBinding binding = Utils.CreateNetTcpBinding();

            byte[] task_data = new byte[input_data_size];
            (new Random()).NextBytes(task_data);

            AutoResetEvent allClientSendEvt   = new AutoResetEvent(false);
            AutoResetEvent allClientDoneEvt   = new AutoResetEvent(false);
            int            clientSendCounting = batchCount;
            int            clientDoneCounting = batchCount;

            data.SendStart = DateTime.Now;

            for (int i = 0; i < batchCount; i++)
            {
                int msg_count = req_count / batchCount;
                if (i == batchCount - 1)
                {
                    msg_count += req_count % batchCount;
                }

                string clientId = Environment.MachineName + "-" + i.ToString() + "-" + Process.GetCurrentProcess().Id.ToString();
                Thread t        = new Thread(new ThreadStart(() =>
                {
                    AutoResetEvent batchDone = new AutoResetEvent(false);

                    using (var client = new BrokerClient <IService1>(clientId, session, binding))
                    {
                        ResponseHandlerBase handler;
                        handler = new ComputeWithInputDataResponseHandler(client, clientId, common_data_size, retryRequestAndIgnoreRetryOperationError);
                        client.SetResponseHandler <ComputeWithInputDataResponse>(((ComputeWithInputDataResponseHandler)handler).ResponseHandler <ComputeWithInputDataResponse>);

                        ClientSendRequest(client, clientId, msg_count, task_data);

                        if (Interlocked.Decrement(ref clientSendCounting) <= 0)
                        {
                            allClientSendEvt.Set();
                        }

                        handler.WaitOne();
                        Log("Client {0}: All requests returned.", clientId);

                        lock (lockobject)
                        {
                            data.ResultCollection.AddRange(handler.results);
                            data.FaultCount = handler.faultCalls;
                        }
                        try
                        {
                            client.Close(durable, 10 * 60 * 1000);
                        }
                        catch (Exception e)
                        {
                            Log("Purge client {0} failed: {1}", clientId, e.ToString());
                        }
                        if (Interlocked.Decrement(ref clientDoneCounting) <= 0)
                        {
                            allClientDoneEvt.Set();
                        }
                    }
                }));
                t.Start();
            }

            allClientSendEvt.WaitOne();
            data.SendEnd = DateTime.Now;
            allClientDoneEvt.WaitOne();
            data.RetrieveEnd = DateTime.Now;
        }