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);
        }
Beispiel #2
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);
        }