コード例 #1
0
ファイル: Program.cs プロジェクト: umialpha/Telepathy
        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
ファイル: Program.cs プロジェクト: umialpha/Telepathy
        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
ファイル: Program.cs プロジェクト: jDolba/dol0039-bp
        static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                name = args[0];
            }

            if (args.Length >= 2)
            {
                headnode = args[1];
            }

            if (args.Length >= 3)
            {
                messageCount = int.Parse(args[2]);
            }

            Console.WriteLine("Creating session...");

            using (Session session = Session.CreateSession(new SessionStartInfo(headnode, "HelloWorld")))
            {
                using (BrokerClient<IHelloWorld> brokerClient = new BrokerClient<IHelloWorld>(session))
                {
                    brokerClient.SetResponseHandler<SayHelloResponse>(ResponseHandler);

                    Console.WriteLine("Sending requests...");

                    for (int i = 0; i < messageCount; i++)
                    {
                        brokerClient.SendRequest(new SayHelloRequest(name));
                    }

                    Console.WriteLine("Committing requests...");

                    brokerClient.EndRequests();

                    Console.WriteLine("Waiting for responses...");
                    Console.ReadLine();
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: umialpha/Telepathy
        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;
        }
コード例 #5
0
        static void Main(string[] args)
        {
            CmdParser parser = new CmdParser(args);
            Config    config = new Config(parser);

            if (config.HelpInfo)
            {
                config.PrintHelp();
                return;
            }

            if (config.Verbose)
            {
                config.PrintUsedParams(parser);
            }

            if (config.PrintUnusedParams(parser))
            {
                config.PrintHelp();
                return;
            }

            // TODO: SessionStartInfoFactory
            SessionStartInfo info = null;

            if (config.IsNoSession)
            {
                // Start session without session manager
                if (config.InprocessBroker)
                {
                    info = new SessionStartInfo(config.ServiceName, config.RegPath, null, config.TargetList?.ToArray());
                    info.UseInprocessBroker = true;
                    info.IsNoSession        = true;
                }
                else
                {
                    info = new SessionStartInfo(config.HeadNode, config.ServiceName, config.RegPath, null, config.TargetList?.ToArray());
                    info.UseInprocessBroker = false;
                    info.IsNoSession        = true;
                }
            }
            else
            {
                info                    = new SessionStartInfo(config.HeadNode, config.ServiceName);
                info.IsNoSession        = false;
                info.UseInprocessBroker = config.InprocessBroker;
            }

            if (!string.IsNullOrEmpty(config.Username))
            {
                info.Username = config.Username;
            }
            if (!string.IsNullOrEmpty(config.Password))
            {
                info.Password = config.Password;
            }
            if (!string.IsNullOrEmpty(config.JobName))
            {
                info.ServiceJobName = config.JobName;
            }

            if (!string.IsNullOrEmpty(config.AzureStorageConnectionString))
            {
                info.AzureStorageConnectionString          = config.AzureStorageConnectionString;
                info.BrokerLauncherStorageConnectionString = config.AzureStorageConnectionString;
            }

            switch (config.ResourceType.ToLowerInvariant())
            {
            case "core":
                info.SessionResourceUnitType = SessionUnitType.Core;
                break;

            case "node":
                info.SessionResourceUnitType = SessionUnitType.Node;
                break;

            case "socket":
                info.SessionResourceUnitType = SessionUnitType.Socket;
                break;

            case "gpu":
                info.SessionResourceUnitType = SessionUnitType.Gpu;
                break;

            default:
                break;
            }
            if (config.MaxResource > 0)
            {
                info.MaximumUnits = config.MaxResource;
            }
            if (config.MinResource > 0)
            {
                info.MinimumUnits = config.MinResource;
            }
            switch (config.TransportScheme.ToLowerInvariant())
            {
            case "nettcp":
                info.TransportScheme = TransportScheme.NetTcp;
                break;

            case "http":
                info.TransportScheme = TransportScheme.Http;
                break;

            case "nethttp":
                info.TransportScheme = TransportScheme.NetHttp;
                break;

            case "custom":
                info.TransportScheme = TransportScheme.Custom;
                break;

            case "azstorage":
                info.TransportScheme = TransportScheme.AzureStorage;
                break;

            default:
                break;
            }

            info.JobTemplate                = config.JobTemplate;
            info.SessionPriority            = config.Priority;
            info.NodeGroupList              = new List <string>(config.NodeGroups.Split(new char[] { ',' }));
            info.RequestedNodesList         = new List <string>(config.Nodes.Split(new char[] { ',' }));
            info.Secure                     = !config.Insecure && !config.IsNoSession;
            info.UseAzureQueue              = config.AzureQueue;
            info.ShareSession               = config.ShareSession;
            info.UseSessionPool             = config.SessionPool;
            info.ParentJobIds               = StringToIntList(config.ParentIds);
            info.ServiceHostIdleTimeout     = config.ServiceIdleSec == -1 ? config.ServiceIdleSec : config.ServiceIdleSec * 1000;
            info.ServiceHangTimeout         = config.ServiceHangSec == -1 ? config.ServiceHangSec : config.ServiceHangSec * 1000;
            info.UseWindowsClientCredential = config.UseWCC;
            info.UseAad                     = config.UseAad;

            if (config.Runtime > 0)
            {
                info.Runtime = config.Runtime;
            }
            if (!string.IsNullOrEmpty(config.Environment))
            {
                foreach (string keyValue in config.Environment.Split(new char[] { ',' }))
                {
                    string[] p = keyValue.Split(new char[] { '=' });
                    if (p.Length == 2)
                    {
                        info.Environments.Add(p[0], p[1]);
                    }
                }
            }

            Stopwatch watch           = new Stopwatch();
            int       timeoutMilliSec = config.MsgTimeoutSec * 1000;

            Dictionary <Guid, Dictionary <Guid, TaskRecord> > brokerClientTaskTimeRecords = new Dictionary <Guid, Dictionary <Guid, TaskRecord> >(config.BrokerClient);
            Dictionary <Guid, DateTime> brokerSendRequestStartTime = new Dictionary <Guid, DateTime>(config.BrokerClient);
            Dictionary <Guid, DateTime> brokerSendRequestEndTime   = new Dictionary <Guid, DateTime>(config.BrokerClient);
            Dictionary <Guid, DateTime> brokerGetResponseStartTime = new Dictionary <Guid, DateTime>(config.BrokerClient);
            Dictionary <Guid, DateTime> brokerGetResponseEndTime   = new Dictionary <Guid, DateTime>(config.BrokerClient);

            Random rTimeMS   = new Random();
            Random rSizeKB   = new Random();
            int    maxTimeMS = 0;
            int    minTimeMS = 0;
            int    maxSizeKB = 0;
            int    minSizeKB = 0;

            if (!string.IsNullOrEmpty(config.TimeMSRandom))
            {
                string[] values = config.TimeMSRandom.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 2)
                {
                    int.TryParse(values[0], out minTimeMS);
                    int.TryParse(values[1], out maxTimeMS);
                }
            }
            if (!string.IsNullOrEmpty(config.SizeKBRandom))
            {
                string[] values = config.SizeKBRandom.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length == 2)
                {
                    int.TryParse(values[0], out minSizeKB);
                    int.TryParse(values[1], out maxSizeKB);
                }
            }

            for (int c = 0; c < config.BrokerClient; c++)
            {
                Dictionary <Guid, TaskRecord> taskTimeReconds = new Dictionary <Guid, TaskRecord>(config.NumberOfRequest);
                for (int i = 0; i < config.NumberOfRequest; i++)
                {
                    Guid       g = Guid.NewGuid();
                    TaskRecord t = new TaskRecord()
                    {
                        RequestTime = DateTime.MinValue, ResponseTime = DateTime.MinValue
                    };
                    if (maxTimeMS > 0)
                    {
                        t.CallDurationMS = rTimeMS.Next(minTimeMS, maxTimeMS);
                    }
                    else
                    {
                        t.CallDurationMS = config.CallDurationMS;
                    }
                    if (maxSizeKB > 0)
                    {
                        t.MessageSizeByte = rSizeKB.Next(minSizeKB, maxSizeKB) * 1024;
                    }
                    else
                    {
                        t.MessageSizeByte = config.MessageSizeByte;
                    }
                    taskTimeReconds.Add(g, t);
                }
                Guid clientGuid = Guid.NewGuid();
                brokerClientTaskTimeRecords.Add(clientGuid, taskTimeReconds);
                brokerSendRequestStartTime.Add(clientGuid, DateTime.MinValue);
                brokerSendRequestEndTime.Add(clientGuid, DateTime.MinValue);
                brokerGetResponseStartTime.Add(clientGuid, DateTime.MinValue);
                brokerGetResponseEndTime.Add(clientGuid, DateTime.MinValue);
            }

            // Create an interactive or durable session
            Logger.Info("Creating a session for CcpEchoSvc service...");
            SessionBase session = null;

            try
            {
                watch.Start();
                if (config.Durable)
                {
                    session = DurableSession.CreateSession(info);
                }
                else
                {
                    session = Session.CreateSession(info);
                }

                watch.Stop();
                Logger.Info("{0, -35} : {1}", "Session ID", session.Id);
                Logger.Info("{0, -35} : {1:F3} sec", "Session creation time", watch.Elapsed.TotalSeconds);

                //session warm up time
                if (config.WarmupTimeSec > 0)
                {
                    Logger.Info("Session warming up in {0} seconds...", config.WarmupTimeSec);
                    Thread.Sleep(config.WarmupTimeSec * 1000);
                }

                int            clientNumber  = config.BrokerClient;
                int            clientCounter = 0;
                AutoResetEvent allDone       = new AutoResetEvent(false);

                foreach (Guid g in brokerClientTaskTimeRecords.Keys)
                {
                    ThreadPool.QueueUserWorkItem((o) =>
                    {
                        Guid brokerClientGuid = (Guid)o;
                        AutoResetEvent done   = new AutoResetEvent(false);
                        int count             = 0;
                        int clientC           = Interlocked.Increment(ref clientCounter);

                        Stopwatch watchT = new Stopwatch();
                        try
                        {
                            // Create a BrokerClient proxy
                            using (BrokerClient <IEchoSvc> client = new BrokerClient <IEchoSvc>(brokerClientGuid.ToString(), session))
                            {
                                if (config.AsyncResponseHandler)
                                {
                                    //set getresponse handler
                                    Logger.Info("Setting response handler ({0}/{1}) to receive responses async.", clientC, config.BrokerClient);
                                    client.SetResponseHandler <GenerateLoadResponse>((item) =>
                                    {
                                        try
                                        {
                                            Guid gg          = item.RequestMessageId;
                                            StatisticInfo si = item.Result.GenerateLoadResult;
                                            if (config.Verbose)
                                            {
                                                Logger.Info("Response async received ({0}/{1}) {2} : {3}. StartTime-EndTime : {4:HH:mm:ss.fff}-{5:HH:mm:ss.fff}", clientC, config.BrokerClient, item.GetUserData <int>(), gg, si.StartTime, si.EndTime);
                                            }
                                            brokerClientTaskTimeRecords[brokerClientGuid][gg].ResponseTime = DateTime.Now;
                                        }
                                        catch (FaultException ex)
                                        {
                                            Logger.Warning("FaultException while getting responses in callback. \n{0}", ex.ToString());
                                        }
                                        catch (RetryOperationException ex)
                                        {
                                            Logger.Warning("RetryOperationException while getting responses in callback. \n{0}", ex.ToString());
                                        }
                                        catch (SessionException ex)
                                        {
                                            Logger.Warning("SessionException while getting responses in callback. \n{0}", ex.ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.Warning("Exception while getting responses in callback. \n{0}", ex.ToString());
                                        }

                                        if (Interlocked.Increment(ref count) == config.NumberOfRequest)
                                        {
                                            done.Set();
                                        }
                                    });
                                }

                                Logger.Info("Sending {0} requests for broker client ({1}/{2})...", config.NumberOfRequest, clientC, config.BrokerClient);
                                brokerSendRequestStartTime[brokerClientGuid] = DateTime.Now;
                                watchT.Restart();
                                int i = 0;
                                foreach (Guid requestGuid in brokerClientTaskTimeRecords[brokerClientGuid].Keys)
                                {
                                    i++;
                                    GenerateLoadRequest request = new GenerateLoadRequest(brokerClientTaskTimeRecords[brokerClientGuid][requestGuid].CallDurationMS, new byte[brokerClientTaskTimeRecords[brokerClientGuid][requestGuid].MessageSizeByte], null);
                                    client.SendRequest <GenerateLoadRequest>(request, i, timeoutMilliSec, new System.Xml.UniqueId(requestGuid));
                                    if (config.Verbose)
                                    {
                                        Logger.Info("Sent request {0} for ({1}/{2}) : {3} : timeMS - {4} sizeByte - {5}", i, clientC, config.BrokerClient, requestGuid, brokerClientTaskTimeRecords[brokerClientGuid][requestGuid].CallDurationMS, brokerClientTaskTimeRecords[brokerClientGuid][requestGuid].MessageSizeByte);
                                    }
                                    brokerClientTaskTimeRecords[brokerClientGuid][requestGuid].RequestTime = DateTime.Now;
                                    if (config.Flush > 0 && i % config.Flush == 0)
                                    {
                                        client.Flush(timeoutMilliSec);
                                    }
                                }

                                // Flush the message
                                client.EndRequests(timeoutMilliSec);
                                watchT.Stop();
                                brokerSendRequestEndTime[brokerClientGuid] = DateTime.Now;
                                double requestElapsedSeconds = watchT.Elapsed.TotalSeconds;
                                double requestThroughput     = config.NumberOfRequest / requestElapsedSeconds;
                                Logger.Info("{0, -35} : {1:F3} sec", string.Format("Requests sent time ({0}/{1})", clientC, config.BrokerClient), requestElapsedSeconds);
                                Logger.Info("{0, -35} : {1:F2} /sec", string.Format("Requests throughput ({0}/{1})", clientC, config.BrokerClient), requestThroughput);

                                if (!config.AsyncResponseHandler)
                                {
                                    Logger.Info("Retrieving responses for broker client ({0}/{1})...", clientC, config.BrokerClient);
                                    try
                                    {
                                        brokerGetResponseStartTime[brokerClientGuid] = DateTime.Now;
                                        watchT.Restart();
                                        int responseNumber = 0;
                                        foreach (BrokerResponse <GenerateLoadResponse> response in client.GetResponses <GenerateLoadResponse>(timeoutMilliSec))
                                        {
                                            try
                                            {
                                                Guid gg          = response.RequestMessageId;
                                                StatisticInfo si = response.Result.GenerateLoadResult;
                                                if (config.Verbose)
                                                {
                                                    Logger.Info("Response received ({0}/{1}) {2} : {3}. StartTime-EndTime : {4:HH:mm:ss.fff}-{5:HH:mm:ss.fff}", clientC, config.BrokerClient, response.GetUserData <int>(), gg, si.StartTime, si.EndTime);
                                                }
                                                else
                                                {
                                                    Logger.Progress(string.Empty, responseNumber, config.NumberOfRequest);
                                                }

                                                brokerClientTaskTimeRecords[brokerClientGuid][gg].ResponseTime = DateTime.Now;
                                            }
                                            catch (FaultException e)
                                            {
                                                // Application exceptions
                                                Logger.Warning("FaultException when getting responses. \n{0}", e.ToString());
                                            }
                                            catch (RetryOperationException e)
                                            {
                                                // RetryOperationExceptions may or may not be recoverable
                                                Logger.Warning("RetryOperationException when getting responses. \n{0}", e.ToString());
                                            }
                                            catch (SessionException e)
                                            {
                                                // Exception
                                                Logger.Warning("SessionException when getting responses. \n{0}", e.ToString());
                                            }
                                            catch (Exception e)
                                            {
                                                // Exception
                                                Logger.Warning("Exception when getting responses. \n{0}", e.ToString());
                                            }
                                            finally
                                            {
                                                responseNumber++;
                                            }
                                        }
                                        watchT.Stop();
                                        brokerGetResponseEndTime[brokerClientGuid] = DateTime.Now;
                                        double elapsedTimeSec = watchT.Elapsed.TotalSeconds;
                                        Logger.Info("{0, -35} : {1:F3} sec", string.Format("GetResponses time ({0}/{1})", clientC, config.BrokerClient), elapsedTimeSec);
                                        Logger.Info("{0, -35} : {1:F2} /sec", string.Format("GetResponses throughput ({0}/{1})", clientC, config.BrokerClient), responseNumber / elapsedTimeSec);
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.Error("Error occured getting responses.\n{0}", ex.ToString());
                                    }
                                }
                                else
                                {
                                    //wait for receiving responses async.
                                    done.WaitOne();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            //swallow the exception in the thread.
                            Logger.Error("Error occured in broker client thread.\n{0}", e.ToString());
                        }

                        if (Interlocked.Decrement(ref clientNumber) == 0)
                        {
                            allDone.Set();
                        }
                    }, g);
                } // for t

                Logger.Info("Wait for all broker clients.");
                allDone.WaitOne();
            }
            catch (Exception e)
            {
                Logger.Error("Error occured.\n{0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    //explict close the session to free the resource
                    session.Close(!config.ShareSession);
                    session.Dispose();
                }
            }

            //calc the request/response throughput for all broker client
            double allRequestsElapsedSeconds = (brokerSendRequestEndTime.Values.Max() - brokerSendRequestStartTime.Values.Min()).TotalSeconds;
            double allRequestThroughput      = config.NumberOfRequest * config.BrokerClient / allRequestsElapsedSeconds;

            Logger.Info("{0, -35} : {1:F3} sec", "All requests sending time", allRequestsElapsedSeconds);
            Logger.Info("{0, -35} : {1:F2} /sec", "All requests throughput", allRequestThroughput);

            double allResponsesElapsedSeconds = (brokerGetResponseEndTime.Values.Max() - brokerGetResponseStartTime.Values.Min()).TotalSeconds;
            double allResponseThroughput      = config.NumberOfRequest * config.BrokerClient / allResponsesElapsedSeconds;

            Logger.Info("{0, -35} : {1:F3} sec", "All resposnes receiving time", allResponsesElapsedSeconds);
            Logger.Info("{0, -35} : {1:F2} /sec", "All responses throughput", allResponseThroughput);


            //calc the min/max/average request e2e time
            double[]   times     = new double[config.NumberOfRequest * config.BrokerClient];
            DateTime[] dates     = new DateTime[config.NumberOfRequest * config.BrokerClient];
            DateTime[] dates_req = new DateTime[config.NumberOfRequest * config.BrokerClient];

            int k = 0;

            foreach (Guid g in brokerClientTaskTimeRecords.Keys)
            {
                foreach (TaskRecord r in brokerClientTaskTimeRecords[g].Values)
                {
                    times[k]     = (r.ResponseTime - r.RequestTime).TotalSeconds;
                    dates[k]     = r.ResponseTime;
                    dates_req[k] = r.RequestTime;
                    k++;
                }
            }

            Logger.Info("{0, -35} : {1:F3} sec", "Response time Min", times.Min());
            Logger.Info("{0, -35} : {1:F3} sec", "Response time Max", times.Max());
            Logger.Info("{0, -35} : {1:F3} sec", "Response time Ave", times.Average());
            DateTime first          = dates.Min();
            DateTime last           = dates.Max();
            DateTime first_req      = dates_req.Min();
            double   elapsedSec     = (last - first).TotalSeconds;
            double   elapsedSec_req = (last - first_req).TotalSeconds;

            Logger.Info("{0, -35} : {1:HH:mm:ss.fff}", "Response first", first);
            Logger.Info("{0, -35} : {1:HH:mm:ss.fff}", "Response last", last);
            Logger.Info("{0, -35} : {1:F3} sec", "Responses elapsed", elapsedSec);
            Logger.Info("{0, -35} : {1:F2} /sec", "Responses throughput", config.NumberOfRequest * config.BrokerClient / elapsedSec);
            Logger.Info("{0, -35} : {1:F3} sec", "Request E2E elapsed", elapsedSec_req);
            Logger.Info("{0, -35} : {1:F2} /sec", "Request E2E throughput", config.NumberOfRequest * config.BrokerClient / elapsedSec_req);
            Logger.Info("Echo Done.");
        }
コード例 #6
0
        static void Main(string[] args)
        {
            //Change headnode here
            const string headnode    = "head.contoso.com";
            const string serviceName = "PrimeFactorizationService";

            SessionStartInfo info = new SessionStartInfo(headnode, serviceName);

            //Enable session pool
            info.ShareSession   = true;
            info.UseSessionPool = true;

            try
            {
                //create an interactive session
                using (Session session = Session.CreateSession(info))
                {
                    Console.WriteLine("Session {0} has been created", session.Id);

                    //in one session, each broker client should have a unique id
                    string ClientId = Guid.NewGuid().ToString();

                    //use this event sync main thread and callback
                    AutoResetEvent done = new AutoResetEvent(false);

                    using (BrokerClient <IPrimeFactorization> client = new BrokerClient <IPrimeFactorization>(ClientId, session))
                    {
                        Console.WriteLine("BrokerClient {0} has been created", ClientId);

                        //set callback function. this handler will be invoke before service replies.
                        client.SetResponseHandler <FactorizeResponse>((response) =>
                        {
                            int number    = response.GetUserData <int>();
                            int[] factors = response.Result.FactorizeResult;

                            Console.WriteLine("{0} = {1}", number,
                                              string.Join <int>(" * ", factors));

                            //release the lock
                            done.Set();
                        });

                        Random random = new Random();
                        int    num    = random.Next(1, Int32.MaxValue);

                        //send request
                        FactorizeRequest request = new FactorizeRequest(num);
                        client.SendRequest <FactorizeRequest>(request, num);

                        client.EndRequests();

                        //wait until callback returns
                        done.WaitOne();
                    }

                    Console.WriteLine("Factorization done.");

                    Console.WriteLine("Press any key to exit");
                    Console.ReadKey();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            const string headnode    = "[headnode]";
            const string serviceName = "EchoService";
            const int    numRequests = 12;
            int          count       = 0;

            SessionStartInfo info = new SessionStartInfo(headnode, serviceName);
            AutoResetEvent   done = new AutoResetEvent(false);

            Console.Write("Creating a session for EchoService...");
            using (Session session = Session.CreateSession(info))
            {
                Console.WriteLine("done session id = {0}", session.Id);
                NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);

                using (BrokerClient <IService1> client = new BrokerClient <IService1>(session, binding))
                {
                    //set getresponse handler
                    client.SetResponseHandler <EchoResponse>((item) =>
                    {
                        try
                        {
                            Console.WriteLine("\tReceived response for request {0}: {1}",
                                              item.GetUserData <int>(), item.Result.EchoResult);
                        }
                        catch (SessionException ex)
                        {
                            Console.WriteLine("SessionException while getting responses in callback: {0}", ex.Message);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Exception while getting responses in callback: {0}", ex.Message);
                        }

                        if (Interlocked.Increment(ref count) == numRequests)
                        {
                            done.Set();
                        }
                    });

                    // start to send requests
                    Console.Write("Sending {0} requests...", numRequests);

                    for (int i = 0; i < numRequests; i++)
                    {
                        EchoRequest request = new EchoRequest("hello world!");
                        client.SendRequest <EchoRequest>(request, i);
                    }
                    client.EndRequests();
                    Console.WriteLine("done");

                    Console.WriteLine("Retrieving responses...");

                    // Main thread block here waiting for the retrieval process
                    // to complete.  As the thread that receives the "numRequests"-th
                    // responses does a Set() on the event, "done.WaitOne()" will pop
                    done.WaitOne();
                    Console.WriteLine("Done retrieving {0} responses", numRequests);
                }

                // Close connections and delete messages stored in the system
                session.Close();
            }

            Console.WriteLine("Press any key to exit.");
            Console.Read();
        }
コード例 #8
0
        public void doSubmit(Dictionary <string, string> runParameters)
        {
            m_start = System.Environment.TickCount;

            //
            // Configure session with cluster:
            //
            string[] parameterKeys = { "HeadNode", "Service", "JobTemplate", "Tasks", "TaskTime" };
            foreach (string parameterKey in parameterKeys)
            {
                if (!runParameters.ContainsKey(parameterKey))
                {
                    outputError(parameterKey);
                }
            }

            string           headNode = runParameters["HeadNode"];
            SessionStartInfo info     = new SessionStartInfo(headNode, runParameters["Service"]);

            info.SessionResourceUnitType = SessionUnitType.Core;
            if (runParameters.ContainsKey("MinCores"))
            {
                info.MinimumUnits = Convert.ToInt32(runParameters["MinCores"]);
            }
            if (runParameters.ContainsKey("MaxCores"))
            {
                info.MaximumUnits = Convert.ToInt32(runParameters["MaxCores"]);
            }
            if (runParameters.ContainsKey("Priority"))
            {
                info.SessionPriority = Convert.ToInt32(runParameters["Priority"]);
            }

            info.Secure = false;                               // generally off in the classroom:
            info.BrokerSettings.SessionIdleTimeout = 15000;    // 15 secs:
            info.JobTemplate = runParameters["JobTemplate"];


            int tasks    = Convert.ToInt32(runParameters["Tasks"]);
            int taskTime = Convert.ToInt32(runParameters["TaskTime"]);

            double taskFailureChance = 0.0;

            if (runParameters.ContainsKey("TaskFailureChance"))
            {
                taskFailureChance = Convert.ToDouble(runParameters["TaskFailureChance"]);
            }
            int taskTimeDeviation = 0;

            if (runParameters.ContainsKey("TaskTimeDeviation"))
            {
                taskTimeDeviation = Convert.ToInt32(runParameters["TaskTimeDeviation"]);
            }
            int taskThrottling = 0;

            if (runParameters.ContainsKey("TaskThrottling"))
            {
                taskThrottling = Convert.ToInt32(runParameters["TaskThrottling"]);
            }

            //
            // User is prompted for run-as credentials, then session
            // is opened for business:
            //
            Session.SetInterfaceMode(false /*GUI*/, (IntPtr)0);
            Console.WriteLine("Creating session: {0}ms", System.Environment.TickCount - m_start);
            using (var session = Session.CreateSession(info))
            {
                Console.WriteLine("Session Created: {0}ms", System.Environment.TickCount - m_start);

                var mode    = (info.Secure) ? SecurityMode.Transport : SecurityMode.None;
                var binding = new NetTcpBinding(mode);
                using (var proxy = new BrokerClient <ClusterTesterService.IClusterTesterService>(session, binding))
                {
                    m_signal = new Semaphore(0, 1);
                    proxy.SetResponseHandler <ClusterTesterService.RunTaskResponse>(doSubmit_ServiceCallback, m_signal);

                    Console.WriteLine("Connected to session {0}: {1}ms", session.Id, System.Environment.TickCount - m_start);

                    //
                    // Make the N service calls:
                    //
                    Console.WriteLine("Sending requests: {0}", System.Environment.TickCount - m_start);
                    Random random = new Random();
                    int    thisTaskTime;
                    for (int i = 0; i < tasks; i++)
                    {
                        if (taskTimeDeviation != 0)
                        {
                            thisTaskTime = Math.Max(0, gaussian(random, taskTime, taskTimeDeviation));
                        }
                        else
                        {
                            thisTaskTime = taskTime;
                        }

                        if (taskThrottling > 0)
                        {
                            Thread.Sleep(taskThrottling);
                        }

                        proxy.SendRequest(new ClusterTesterService.RunTaskRequest(i, thisTaskTime, taskFailureChance));
                    }
                    proxy.EndRequests();
                    Console.WriteLine("End requests: {0}ms", System.Environment.TickCount - m_start);

                    //
                    // wait on callbacks
                    //
                    m_signal.WaitOne();
                    session.Close();
                }
            }

            Console.WriteLine("Exit program: {0}ms", System.Environment.TickCount - m_start);
            m_stop = System.Environment.TickCount;
        }