Example #1
0
        static void Main(string[] args)
        {
            var prog = new ChirperNetworkLoader();
            int exitCode;

            AssemblyName thisProg  = Assembly.GetExecutingAssembly().GetName();
            string       progTitle = string.Format("{0} v{1}",
                                                   thisProg.Name,
                                                   thisProg.Version);

            Console.WriteLine(progTitle);
            Console.Title = progTitle;

            try
            {
                if (!prog.ParseArguments(args))
                {
                    prog.PrintUsage();
                    exitCode = -1;
                }
                else
                {
                    Task <int> run = prog.Run();

                    // Note: Unfortunately we can't use await in Main method.
                    bool ok = run.Wait(timeout);

                    if (run.IsFaulted)
                    {
                        Console.WriteLine("Error running client program: " + run.Exception);
                        prog.DumpStatus();
                        exitCode = 1;
                    }
                    else if (!ok)
                    {
                        Console.WriteLine("Timeout running client program");
                        prog.DumpStatus();
                        exitCode = 2;
                    }
                    else
                    {
                        exitCode = run.Result;
                    }
                }
            }
            catch (Exception exc)
            {
                prog.ReportError(thisProg.Name + " halting due to error", exc);
                exitCode = 1;
            }

            // if we printed usage, we don't need to display statistics.
            if (exitCode != -1)
            {
                prog.WaitForCompletion();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            var prog = new ChirperNetworkLoader();
            int exitCode;
                
            AssemblyName thisProg = Assembly.GetExecutingAssembly().GetName();
            string progTitle = string.Format("{0} v{1}",
                thisProg.Name,
                thisProg.Version);
            Console.WriteLine(progTitle);
            Console.Title = progTitle;

            try
            {
                if (!prog.ParseArguments(args))
                {
                    prog.PrintUsage();
                    exitCode = -1;
                }
                else
                {
                    Task<int> run = prog.Run();

                    // Note: Unfortunately we can't use await in Main method.
                    bool ok = run.Wait(timeout);

                    if (run.IsFaulted)
                    {
                        Console.WriteLine("Error running client program: " + run.Exception);
                        prog.DumpStatus();
                        exitCode = 1;
                    }
                    else if (!ok)
                    {
                        Console.WriteLine("Timeout running client program");
                        prog.DumpStatus();
                        exitCode = 2;
                    }
                    else
                    {
                        exitCode = run.Result;
                    }
                }
            }
            catch (Exception exc)
            {
                prog.ReportError(thisProg.Name + " halting due to error", exc);
                exitCode = 1;
            }

            // if we printed usage, we don't need to display statistics.
            if (exitCode != -1)
            {
                prog.WaitForCompletion();
            }
        }
Example #3
0
        public int Run()
        {
            this.perfCounters = new ChirperPerformanceCounters(this.GraphDataFile.FullName);
            perfCounters.ChirpsPerSecond.RawValue = 0;

            pipeline = new AsyncPipeline(PipelineLength);
            loader = new ChirperNetworkLoader(pipeline);
            //if (this.Verbose) loader.SetVerbose();

            Console.WriteLine("Loading Chirper network data file " + this.GraphDataFile.FullName);
            loader.FileToLoad = this.GraphDataFile;
            loader.LoadData();
            loader.CreateUserNodes(); // Connect/create users

            Console.WriteLine(
                "Starting Chirper network traffic simulation for {0} users.\n"
                + "Chirp publication time base = {1}\n"
                + "Random time distribution = {2}\n"
                + "Rechirp rate = {3}", 
                loader.Users.Count, this.ChirpPublishTimebase, this.ChirpPublishTimeRandom, this.ShouldRechirpRate);

            ForEachUser(user =>
            {
                SimulatedUser u = new SimulatedUser(user);
                u.ShouldRechirpRate = this.ShouldRechirpRate;
                u.ChirpPublishTimebase = this.ChirpPublishTimebase;
                u.ChirpPublishTimeRandom = this.ChirpPublishTimeRandom;
                u.Verbose = this.Verbose;
                lock (activeUsers)
                {
                    activeUsers.Add(u);
                }
                u.Start();
            });

            Console.WriteLine("Starting sending chirps...");

            Random rand = new Random();
            int count = 0;
            Stopwatch stopwatch = Stopwatch.StartNew();
            do
            {
                int i = rand.Next(activeUsers.Count);
                SimulatedUser u = activeUsers[i];
                if (u == null)
                {
                    Console.WriteLine("User {0} not found.", i);
                    return -1;
                }

                string msg = fortune.GetFortune();

                pipeline.Add(u.PublishMessage(msg));
                count++;
                if (count % 10000 == 0)
                {
                    Console.WriteLine("{0:0.#}/sec: {1} in {2}ms.  Pipeline contains {3} items.",
                        ((float)10000 / stopwatch.ElapsedMilliseconds) * 1000, count, stopwatch.ElapsedMilliseconds, pipeline.Count);
                    perfCounters.ChirpsPerSecond.RawValue = (int) (((float) 10000 / stopwatch.ElapsedMilliseconds) * 1000);

                    stopwatch.Restart();
                }

                if (ChirpPublishTimebase > 0)
                {
                    Thread.Sleep(ChirpPublishTimebase * 1000);
                }
            } while (true);
        }