Exemplo n.º 1
0
        private void perfMon_ValueUpdated(object sender, EventArgs e)
        {
            long     num = -1L;
            DateTime now = DateTime.Now;

            if (this.isProfileThread)
            {
                for (int i = 0; i < this.profilers.Count; i++)
                {
                    JobProfiler jobProfiler = this.profilers[i];
                    if (jobProfiler != null && now.Subtract(jobProfiler.CalculatedTime).TotalMinutes <= 1.0)
                    {
                        double num2 = ((ProfileIndex <double>)jobProfiler.CalculatedValue).WaitTimeIndex * 100.0;
                        Log <MMOChannelService> .Logger.DebugFormat("{0} thread index {1}", i, num2);

                        if ((long)num2 > num)
                        {
                            num = (long)num2;
                        }
                    }
                }
                if (num < 0L)
                {
                    if (this.ThreadCount > 0)
                    {
                        Log <MMOChannelService> .Logger.Error("no profiler index - all thread dead?");

                        num = 100L;
                    }
                    else
                    {
                        num = (long)((int)this.perfMon.CpuPercentTotal);
                    }
                }
            }
            else
            {
                num = (long)((int)this.perfMon.CpuPercentTotal);
            }
            this.CurrentLoad = num;
            foreach (int serviceID in base.LookUp.FindIndex(base.Category))
            {
                SyncLoad op = new SyncLoad
                {
                    ServiceID = base.ID,
                    Load      = num
                };
                base.RequestOperation(serviceID, op);
            }
        }
Exemplo n.º 2
0
        private void InitializeThreads()
        {
            foreach (JobProcessor jobProcessor in this.threads)
            {
                jobProcessor.Stop();
            }
            foreach (JobProfiler jobProfiler in this.profilers)
            {
                jobProfiler.Unbind();
            }
            this.threads   = new List <JobProcessor>();
            this.profilers = new List <JobProfiler>();
            if (this.ThreadCount <= 0)
            {
                return;
            }
            int i;

            for (i = 0; i < this.ThreadCount; i++)
            {
                JobProcessor jobProcessor2 = base.AcquireNewThread();
                this.threads.Add(jobProcessor2);
                jobProcessor2.ExceptionOccur += delegate(object sender, EventArgs <Exception> arg)
                {
                    Log <MMOChannelService> .Logger.Error(string.Format("Unhandled Exception from Thread{0} : ", i), arg.Value);
                };
                this.isProfileThread = ServiceCore.FeatureMatrix.IsEnable("MMOThreadProfile");
                if (this.isProfileThread)
                {
                    JobProfiler jobProfiler2 = new JobProfiler(new AverageProfilePolicy())
                    {
                        CalculateIntervalMilliSecs = 30000
                    };
                    jobProfiler2.ExceptionOccur += delegate(object sender, EventArgs <Exception> arg)
                    {
                        Log <MMOChannelService> .Logger.Error(string.Format("Unhandled Exception from Thread{0} profiler : ", i), arg.Value);
                    };
                    jobProfiler2.Bind(jobProcessor2);
                    this.profilers.Add(jobProfiler2);
                }
                jobProcessor2.Start();
            }
        }
Exemplo n.º 3
0
        public long RecommendChannel()
        {
            long   num  = -1L;
            double num2 = 1.0;
            List <JobProcessor> list = new List <JobProcessor>();
            bool flag = false;

            if (this.isProfileThread && !ServiceCore.FeatureMatrix.IsEnable("MMOForceRecommend"))
            {
                for (int i = 0; i < this.profilers.Count; i++)
                {
                    JobProfiler jobProfiler = this.profilers[i];
                    if (jobProfiler != null)
                    {
                        if (num2 > ((ProfileIndex <double>)jobProfiler.CalculatedValue).WaitTimeIndex)
                        {
                            flag = true;
                        }
                        else
                        {
                            list.Add(this.threads[i]);
                        }
                    }
                }
                if (!flag && this.ThreadCount > 0)
                {
                    Log <MMOChannelService> .Logger.Warn("all threads are busy");

                    return(-1L);
                }
            }
            foreach (KeyValuePair <long, Channel> keyValuePair in this.channels)
            {
                Channel value = keyValuePair.Value;
                if (!list.Contains(value.Tag as JobProcessor))
                {
                    ChannelEntity channelEntity = value.Entity as ChannelEntity;
                    int           num3          = (channelEntity == null) ? 0 : channelEntity.Count;
                    if (num3 < (int)((double)this.Capacity * 0.8) && (num < 0L || keyValuePair.Key < num))
                    {
                        num = keyValuePair.Key;
                    }
                }
            }
            if (num == -1L)
            {
                Log <MMOChannelService> .Logger.Warn("no channel to recommend");

                if (Log <MMOChannelService> .Logger.IsWarnEnabled)
                {
                    foreach (KeyValuePair <long, Channel> keyValuePair2 in this.channels)
                    {
                        Channel value2 = keyValuePair2.Value;
                        if (!list.Contains(value2.Tag as JobProcessor))
                        {
                            ChannelEntity channelEntity2 = value2.Entity as ChannelEntity;
                            int           num4           = (channelEntity2 == null) ? 0 : channelEntity2.Count;
                            Log <MMOChannelService> .Logger.WarnFormat("{0} channel count : {1}", keyValuePair2.Key, num4);
                        }
                    }
                }
            }
            return(num);
        }