示例#1
0
        private int DoSerialTasksWithRate()
        {
            InitTasksArray();
            long delayStep = (perMin ? 60000 : 1000) / rate;
            long nextStartTime = J2N.Time.CurrentTimeMilliseconds();
            int count = 0;
            long t0 = J2N.Time.CurrentTimeMilliseconds();
            for (int k = 0; (repetitions == REPEAT_EXHAUST && !exhausted) || k < repetitions; k++)
            {
                if (Stop)
                {
                    break;
                }
                for (int l = 0; l < tasksArray.Length; l++)
                {
                    PerfTask task = tasksArray[l];
                    while (!Stop)
                    {
                        long waitMore = nextStartTime - J2N.Time.CurrentTimeMilliseconds();
                        if (waitMore > 0)
                        {
                            // TODO: better to use condition to notify
                            Thread.Sleep(1);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Stop)
                    {
                        break;
                    }
                    nextStartTime += delayStep; // this aims at avarage rate.
                    try
                    {
                        int inc = task.RunAndMaybeStats(letChildReport);
                        count += inc;
                        if (countsByTime != null)
                        {
                            int slot = (int)((J2N.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
                            if (slot >= countsByTime.Length)
                            {
                                countsByTime = ArrayUtil.Grow(countsByTime, 1 + slot);
                            }
                            countsByTime[slot] += inc;
                        }

                        if (anyExhaustibleTasks)
                            UpdateExhausted(task);
                    }
                    catch (NoMoreDataException /*e*/)
                    {
                        exhausted = true;
                    }
                }
            }
            Stop = false;
            return count;
        }
示例#2
0
 public override void Run()
 {
     try
     {
         count = task.RunAndMaybeStats(letChildReport);
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString(), e);
     }
 }
示例#3
0
 public override void Run()
 {
     try
     {
         count = task.RunAndMaybeStats(letChildReport);
     }
     catch (Exception e) when(e.IsException())
     {
         throw RuntimeException.Create(e);
     }
 }
示例#4
0
 public override void Run()
 {
     try
     {
         int n = task.RunAndMaybeStats(outerInstance.letChildReport);
         if (outerInstance.anyExhaustibleTasks)
         {
             outerInstance.UpdateExhausted(task);
         }
         count += n;
     }
     catch (NoMoreDataException)
     {
         outerInstance.exhausted = true;
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString(), e);
     }
 }
示例#5
0
        private int DoSerialTasks()
        {
            if (rate > 0)
            {
                return(DoSerialTasksWithRate());
            }

            InitTasksArray();
            int count = 0;

            long runTime = (long)(runTimeSec * 1000);
            List <RunBackgroundTask> bgTasks = null;

            long t0 = Support.Time.CurrentTimeMilliseconds();

            for (int k = 0; fixedTime || (repetitions == REPEAT_EXHAUST && !exhausted) || k < repetitions; k++)
            {
                if (Stop)
                {
                    break;
                }
                for (int l = 0; l < tasksArray.Length; l++)
                {
                    PerfTask task = tasksArray[l];
                    if (task.RunInBackground)
                    {
                        if (bgTasks == null)
                        {
                            bgTasks = new List <RunBackgroundTask>();
                        }
                        RunBackgroundTask bgTask = new RunBackgroundTask(task, letChildReport);
#if FEATURE_THREAD_PRIORITY
                        bgTask.Priority = (task.BackgroundDeltaPriority + Thread.CurrentThread.Priority);
#endif
                        bgTask.Start();
                        bgTasks.Add(bgTask);
                    }
                    else
                    {
                        try
                        {
                            int inc = task.RunAndMaybeStats(letChildReport);
                            count += inc;
                            if (countsByTime != null)
                            {
                                int slot = (int)((Support.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
                                if (slot >= countsByTime.Length)
                                {
                                    countsByTime = ArrayUtil.Grow(countsByTime, 1 + slot);
                                }
                                countsByTime[slot] += inc;
                            }
                            if (anyExhaustibleTasks)
                            {
                                UpdateExhausted(task);
                            }
                        }
                        catch (NoMoreDataException /*e*/)
                        {
                            exhausted = true;
                        }
                    }
                }
                if (fixedTime && Support.Time.CurrentTimeMilliseconds() - t0 > runTime)
                {
                    repetitions = k + 1;
                    break;
                }
            }

            if (bgTasks != null)
            {
                foreach (RunBackgroundTask bgTask in bgTasks)
                {
                    bgTask.StopNow();
                }
                foreach (RunBackgroundTask bgTask in bgTasks)
                {
                    bgTask.Join();
                    count += bgTask.Count;
                }
            }

            if (countsByTime != null)
            {
                RunData.Points.CurrentStats.SetCountsByTime(countsByTime, logByTimeMsec);
            }

            Stop = false;

            return(count);
        }
示例#6
0
        private int DoSerialTasks()
        {
            if (rate > 0)
            {
                return(DoSerialTasksWithRate());
            }

            InitTasksArray();
            int count = 0;

            long runTime = (long)(runTimeSec * 1000);
            IList <RunBackgroundTask> bgTasks = null;

            long t0 = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results

            for (int k = 0; fixedTime || (repetitions == REPEAT_EXHAUST && !exhausted) || k < repetitions; k++)
            {
                if (Stop)
                {
                    break;
                }
                for (int l = 0; l < tasksArray.Length; l++)
                {
                    PerfTask task = tasksArray[l];
                    if (task.RunInBackground)
                    {
                        if (bgTasks is null)
                        {
                            bgTasks = new JCG.List <RunBackgroundTask>();
                        }
                        RunBackgroundTask bgTask = new RunBackgroundTask(task, letChildReport);
                        bgTask.Priority = (task.BackgroundDeltaPriority + Thread.CurrentThread.Priority);
                        bgTask.Start();
                        bgTasks.Add(bgTask);
                    }
                    else
                    {
                        try
                        {
                            int inc = task.RunAndMaybeStats(letChildReport);
                            count += inc;
                            if (countsByTime != null)
                            {
                                int slot = (int)(((J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) - t0) / logByTimeMsec); // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                                if (slot >= countsByTime.Length)
                                {
                                    countsByTime = ArrayUtil.Grow(countsByTime, 1 + slot);
                                }
                                countsByTime[slot] += inc;
                            }
                            if (anyExhaustibleTasks)
                            {
                                UpdateExhausted(task);
                            }
                        }
                        catch (NoMoreDataException /*e*/)
                        {
                            exhausted = true;
                        }
                    }
                }
                if (fixedTime && (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) - t0 > runTime) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                {
                    repetitions = k + 1;
                    break;
                }
            }

            if (bgTasks != null)
            {
                foreach (RunBackgroundTask bgTask in bgTasks)
                {
                    bgTask.StopNow();
                }
                foreach (RunBackgroundTask bgTask in bgTasks)
                {
                    bgTask.Join();
                    count += bgTask.Count;
                }
            }

            if (countsByTime != null)
            {
                RunData.Points.CurrentStats.SetCountsByTime(countsByTime, logByTimeMsec);
            }

            Stop = false;

            return(count);
        }