Ejemplo n.º 1
0
 public void DeferJob(PlanItemEntryPoint job)
 {
     this.DeferJob(new PlanItem
     {
         JobEntry           = job,
         NameAndDescription = "deffered job"
     });
 }
Ejemplo n.º 2
0
        public void ExecutionPlan_CheckForExecution()
        {
            // check for job executed in same time
            uint localVar          = 0;
            bool notSucceeded      = false;
            PlanItemEntryPoint job = (ThreadContext ti, PlanItem pi) =>
            {
                //Console.WriteLine("ExecutionPlan_CheckForExecution er {0}", System.Threading.Thread.CurrentThread.Name);

                for (int i = 0; i < 1000; i++)
                {
                    localVar++;
                }
                System.Threading.Thread.Sleep(400);
                localVar = 0;
                System.Threading.Thread.Sleep(100);
                if (localVar != 0)
                {
                    notSucceeded = true;
                }

                for (int i = 0; i < 1000; i++)
                {
                    localVar++;
                }
                //Console.WriteLine("ExecutionPlan_CheckForExecution ex {0}", System.Threading.Thread.CurrentThread.Name);
                return(1);
            };
            List <PlanItem> TaskList = new List <PlanItem>()
            {
                new PlanItem()
                {
                    intervalType       = IntervalType.withoutInterval,
                    NameAndDescription = "",
                    JobEntry           = job
                },
            };

            Scheduler.SetPlan(TaskList);
            Scheduler.ReWake();

            System.Threading.Thread.Sleep(1500);

            Scheduler.SuspendAll();
            while (Scheduler.Activity)
            {
                System.Threading.Thread.Sleep(0);
            }
            //
            Assert.AreEqual(notSucceeded, false);

            Assert.AreNotEqual(localVar, 0);
            Assert.AreEqual(localVar, 1000);
        }
Ejemplo n.º 3
0
        static void Scheduler_PayloadToOverallTime_VScale(
            uint step
            , uint steps
            , uint jobsCount
            , uint ThreadsCount
            , uint stepSyncFactor)// interlock granulation actually
        {
            TaskScheduler.ThreadPool Scheduler = new TaskScheduler.ThreadPool(ThreadsCount);


            TimeSpan cspan = new TimeSpan();


            //uint localVar = 0, incVal = 10, maxVal = 10000000;
            int localVar = 0, incVal = (int)step, maxVal = (int)(step * steps), syncStep = (int)(step / stepSyncFactor);

            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < maxVal; i++)
            {
                localVar++;
                //System.Threading.Interlocked.Increment(ref localVar);
                //if (localVar % incVal == 0)
                //    System.Threading.Thread.Sleep(0);
            }
            cspan = sw.Elapsed;
            //Console.WriteLine(cspan.TotalMilliseconds);

            //			sw = Stopwatch.StartNew();
            //			for (int i = 0; i < maxVal; i++) {
            //				localVar++;
            //			}
            //			cspan = sw.Elapsed;
            //			Console.WriteLine(cspan.TotalMilliseconds);

            localVar = 0;
            bool      notSucceeded = true;
            Stopwatch swx_parallel = null;
            {
                Thread[] ths = new Thread[steps];
                swx_parallel = Stopwatch.StartNew();
                for (int i = 0; i < steps; i++)
                {
                    ths[i] = new Thread(() =>
                    {
                        //for (int x = 0; x < incVal; x++)
                        //{
                        //    System.Threading.Interlocked.Increment(ref localVar);
                        //}
                        int tempInc = 0;
                        for (int x = 0; x < syncStep; x++)
                        {
                            for (int y = 0; y < stepSyncFactor; y++)
                            {
                                tempInc++;
                            }
                            Interlocked.Add(ref localVar, tempInc);
                            tempInc = 0;
                        }
                        if (localVar >= maxVal)
                        {
                            notSucceeded = false;
                        }
                    });
                    ths[i].Start();
                }
                while (notSucceeded)
                {
                    System.Threading.Thread.Sleep(0);
                }
                swx_parallel.Stop();
            }
            TimeSpan payloadspan_parallel = swx_parallel.Elapsed;

            localVar     = 0;
            notSucceeded = true;

            PlanItemEntryPoint job = (ThreadContext ti, PlanItem pi) =>
            {
                //Console.WriteLine("ex started {0} {1}", ti.hThread.Name, localVar);
                //for (int i = 0; i < incVal; i++)
                //{
                //    //localVar++;
                //    System.Threading.Interlocked.Increment(ref localVar);
                //}
                int tempInc = 0;
                for (int x = 0; x < syncStep; x++)
                {
                    for (int y = 0; y < stepSyncFactor; y++)
                    {
                        tempInc++;
                    }
                    Interlocked.Add(ref localVar, tempInc);
                    tempInc = 0;
                }
                //System.Threading.Thread.Sleep(0);
                if (localVar >= maxVal)
                {
                    notSucceeded = false;
                }
                //Console.WriteLine("succ executed");
                return(-1);
            };

            List <PlanItem> TaskList = new List <PlanItem>();

            for (int i = 0; i < jobsCount; i++)
            {
                TaskList.Add(new PlanItem()
                {
                    intervalType       = TaskUniversum.Task.IntervalType.withoutInterval,
                    NameAndDescription = "",
                    JobEntry           = job
                });
            }

            //Console.WriteLine("jobs: {0}", TaskList.Count);

            Stopwatch swx = Stopwatch.StartNew();

            Scheduler.SetPlan(TaskList);
            Scheduler.ReWake();

            while (notSucceeded)
            {
                System.Threading.Thread.Sleep(0);
            }
            swx.Stop();
            TimeSpan payloadspan = swx.Elapsed;

            Scheduler.SuspendAll();
            //Console.WriteLine("e act");
            while (Scheduler.Activity)
            {
                System.Threading.Thread.Sleep(0);
            }

            //

            //Console.WriteLine("{0} by {2} --- {3:.00} :: {4} {5} {6} {7}",
            //Console.WriteLine("{0} {2} {9:.00} {3:.00} {8:.00} {4} {5} {6} {7}",
            //    cspan.TotalMilliseconds, cspan.TotalMilliseconds,// * (maxVal / incVal),
            //    payloadspan.TotalMilliseconds,
            //    //(payloadspan.TotalMilliseconds * (maxVal / incVal)) / cspan.TotalMilliseconds);
            //    payloadspan.TotalMilliseconds / cspan.TotalMilliseconds,
            //     step, steps, jobsCount, ThreadsCount,
            //     payloadspan.TotalMilliseconds / payloadspan_parallel.TotalMilliseconds,
            //     payloadspan_parallel.TotalMilliseconds);

            Console.WriteLine("{0:0.00} {1:0.00} {2:0.00} {3:0.00} {4:0.00} {5} {6} {7}"
                              , cspan.TotalMilliseconds
                              , payloadspan.TotalMilliseconds
                              , payloadspan_parallel.TotalMilliseconds
                              , payloadspan.TotalMilliseconds / cspan.TotalMilliseconds
                              , payloadspan.TotalMilliseconds / payloadspan_parallel.TotalMilliseconds
                              , jobsCount
                              , ThreadsCount
                              , stepSyncFactor);
        }
Ejemplo n.º 4
0
        static void Scheduler_PayloadToOverallTime()
        {
            TaskScheduler.ThreadPool Scheduler = new TaskScheduler.ThreadPool();

            TimeSpan cspan = new TimeSpan();


            uint localVar = 0, incVal = 10, maxVal = 10000;

            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < maxVal; i++)
            {
                localVar++;
                if (localVar % incVal == 0)
                {
                    System.Threading.Thread.Sleep(1);
                }
            }
            cspan = sw.Elapsed;
            Console.WriteLine(cspan.TotalMilliseconds);

            //			sw = Stopwatch.StartNew();
            //			for (int i = 0; i < maxVal; i++) {
            //				localVar++;
            //			}
            //			cspan = sw.Elapsed;
            //			Console.WriteLine(cspan.TotalMilliseconds);

            localVar = 0;

            bool notSucceeded      = true;
            PlanItemEntryPoint job = (ThreadContext ti, PlanItem pi) =>
            {
                //Console.WriteLine("ex started {0} {1}", ti.hThread.Name, localVar);
                for (int i = 0; i < incVal; i++)
                {
                    localVar++;
                }
                System.Threading.Thread.Sleep(1);
                if (localVar >= maxVal)
                {
                    notSucceeded = false;
                }
                //Console.WriteLine("succ executed");
                return(-1);
            };
            List <PlanItem> TaskList = new List <PlanItem>()
            {
                new PlanItem()
                {
                    intervalType       = TaskUniversum.Task.IntervalType.withoutInterval,
                    NameAndDescription = "",
                    JobEntry           = job
                },
            };


            Scheduler.ReWake();
            Stopwatch swx = Stopwatch.StartNew();

            Scheduler.SetPlan(TaskList);

            while (notSucceeded)
            {
                System.Threading.Thread.Sleep(0);
            }
            TimeSpan payloadspan = swx.Elapsed;

            Scheduler.SuspendAll();
            Console.WriteLine("e act");
            //while (Scheduler.Activity)
            //{
            //}

            //

            Console.WriteLine("{0}({1}) by {2} --- {3:.00}",
                              cspan.TotalMilliseconds, cspan.TotalMilliseconds, // * (maxVal / incVal),
                              payloadspan.TotalMilliseconds,
                                                                                //(payloadspan.TotalMilliseconds * (maxVal / incVal)) / cspan.TotalMilliseconds);
                              payloadspan.TotalMilliseconds / cspan.TotalMilliseconds);
        }
Ejemplo n.º 5
0
 public void DeferJob(PlanItemEntryPoint job)
 {
     this.DeferJob(new PlanItem
     {
         JobEntry = job,
         NameAndDescription = "deffered job"
     });
 }