Пример #1
0
        private String CollectDelays()
        {
            var result = "";
            int count  = Random.Next(4) + 1;
            int delay  = 0;

            if (Tweaker.Lookup(hostname).ConsumeBandwith > 0)
            {
                int consumeBandwidthBps = Tweaker.Lookup(hostname).ConsumeBandwith;

                if (consumeBandwidthBps < Constants.MAX_BANDWIDTH_BPS * 0.7)
                {
                    delay = 0;
                }
                else if (consumeBandwidthBps >= Constants.MAX_BANDWIDTH_BPS)
                {
                    delay = 400 + Random.Next(300);
                }
                else
                {
                    double modifier = (consumeBandwidthBps - Constants.MAX_BANDWIDTH_BPS * 0.7) / (Constants.MAX_BANDWIDTH_BPS * 0.3);
                    delay = (int)(400 * modifier);
                }
            }

            int addLatency = Tweaker.Lookup(hostname).AddLatency;

            for (int i = 0; i <= count; i++)
            {
                result += (delay + Random.Next(70) + addLatency) + (i == count ? "" : ", ");
            }
            return(result);
        }
Пример #2
0
 internal static Tweaker Lookup(string hostname)
 {
     if (!Instances.ContainsKey(hostname))
     {
         Instances[hostname] = new Tweaker(hostname);
     }
     return(Instances[hostname]);
 }
Пример #3
0
        private String CollectPerformance()
        {
            int consumeCores = Tweaker.Lookup(hostname).ConsumeCores;

            if (consumeCores == Constants.NUM_CORES /*All cores */)
            {
                return((1 + Random.Next(4)).ToString());
            }

            int candidate = 89 + Random.Next(12);

            if (consumeCores == 0)
            {
                return(candidate.ToString());
            }

            double modifier = 1 - ((double)consumeCores / Constants.NUM_CORES);

            return(((int)(candidate * modifier)).ToString());
        }
Пример #4
0
        /// <summary>
        /// Runs a tweaker task on the given host name using the given Tweaker
        /// </summary>
        /// <param name="task">A TweakerTask to run</param>
        /// <param name="tweaker">The Tweaker to run the task on</param>
        /// <param name="hostname">The host name that will be subjected to the tweak</param>
        /// <returns>Result of task, format depends on task type</returns>
        internal static TaskResult RunTask(TweakerTask task, Tweaker tweaker, string hostname)
        {
            var taskResult = new TaskResult()
            {
                Task = task
            };

            var tweak = ValidateAndCorrectTask(task, hostname);

            tweaker.Tweak(task.Mode, tweak);

            string resultMessage = "Tweaker mode " + task.Mode + " applied with value " + tweak;

            return(new TaskResult()
            {
                Messages = new List <String>()
                {
                    resultMessage
                },
                Task = task
            });
        }