comp.lang.ada
 help / color / mirror / Atom feed
From: alby.gamper@gmail.com
Subject: Re: Large number of tasks slows down my program (using debian) - any fix?
Date: Mon, 2 Apr 2018 00:12:02 -0700 (PDT)
Date: 2018-04-02T00:12:02-07:00	[thread overview]
Message-ID: <48c85281-e18f-419f-b498-e87d60d28173@googlegroups.com> (raw)
In-Reply-To: <f25f9607-82be-4eda-be3d-ade20724d610@googlegroups.com>

On Monday, April 2, 2018 at 4:23:43 PM UTC+10, alby....@gmail.com wrote:
> On Friday, March 30, 2018 at 8:04:19 PM UTC+11, Dmitry A. Kazakov wrote:
> > On 2018-03-30 00:33, Shark8 wrote:
> > 
> > > Hm, you shouldn't be hitting the limit with so few tasks. (500 sounds like a lot, but most OSes you'll be using use an integer-ID; meaning something on the order of 2**32 or 2**64.)
> > 
> > It is a simple calculation. Assuming a context switch were around 
> > 1000ns. x 500 tasks / 4 cores = 125ms if all tasks are busy. 125ms is a 
> > long time.
> > 
> > Another factor is scheduling. Assuming the time quant is 10ms (Windows 
> > default) and all task are doing pure calculations uninterrupted by any 
> > I/O, then, again: 10 x 500 / 4 = 1.25s [+125ms] is the time a task gets 
> > back to a core. 1.3s is an eternity.
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> Hi All
> I've done a quick mock-up test which just shows the activation time of 500 tasks
> This is the code, targeting windows (x64). Results show 40 & 45 ms for the two
> cases (running on a Intel Core i7-2600 cpu running @ 3.4 GHz)
> 
> with Ada.Text_IO;                       use Ada.Text_IO;
> procedure AdaTasking is
> 
>     type Bool is new Integer;
>     type Large_Integer is mod 2 ** 64;
> 
>     task type Worker is
>     end;
> 
>     task body Worker is
>     begin
>         null;
>     end;
> 
>     task type WorkerWithEntry is
>         entry Start;
>         entry Stop;
>     end;
> 
>     task body WorkerWithEntry is
>     begin
>         accept Start;
>         null;
>         accept Stop;
>     end;
> 
>     function QueryPerformanceFrequency( lpFrequency : access Large_Integer) return Bool;
>     pragma import (stdcall , QueryPerformanceFrequency , "QueryPerformanceFrequency");
> 
>     function QueryPerformanceCounter( lpPerformanceCount : access Large_Integer) return Bool;
>     pragma import (stdcall , QueryPerformanceCounter , "QueryPerformanceCounter");
> 
>     Ok          : Bool := 0;
>     Frequency   : aliased Large_Integer := 0;
>     StartTime   : aliased Large_Integer := 0;
>     EndTime     : aliased Large_Integer := 0;
>     ElapsedTime : aliased Large_Integer := 0;
>     
> begin
> 
>     Ok := QueryPerformanceFrequency(Frequency'access);
>     Frequency := Frequency / 1000; -- units is ms (ie milli seconds)
>     
>     Ok := QueryPerformanceCounter(StartTime'access);
> 	declare
>         Worker_Pool : array (1..500) of Worker;
>     begin
>         for i in Worker_Pool'Range loop
>             null;
>         end loop;
>     end;
>     Ok := QueryPerformanceCounter(EndTime'access);
>     ElapsedTime := (EndTime-StartTime) / Frequency;
>     Put_Line("Worker          Elapsed Time = " & ElapsedTime'Image & " (ms)");
> 
>     Ok := QueryPerformanceCounter(StartTime'access);
> 	declare
>         Worker_Pool : array (1..500) of WorkerWithEntry;
>     begin
>         for i in Worker_Pool'Range loop
>             Worker_Pool(i).Start;
>             Worker_Pool(i).Stop;
>         end loop;
>     end;
>     Ok := QueryPerformanceCounter(EndTime'access);
>     ElapsedTime := (EndTime-StartTime) / Frequency;
>     Put_Line("WorkerWithEntry Elapsed Time = " & ElapsedTime'Image & " (ms)");
> 
> end;

Note: That rounding errors will occur due to the Large_integer divisions, Which
can be somewhat mitigated by scaling the result to us (ie micro seconds). This
can be done by dividing the frequency by 1,000,000 rather than 1,000.

The revised results are ~44,000 us and ~49000 us  


  reply	other threads:[~2018-04-02  7:12 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 18:06 Large number of tasks slows down my program (using debian) - any fix? reinert
2018-03-28 18:49 ` Dennis Lee Bieber
2018-03-28 19:06 ` Paul Rubin
2018-03-28 19:21 ` Dmitry A. Kazakov
2018-03-28 20:17   ` reinert
2018-03-29  8:46     ` reinert
2018-03-29  9:18       ` Dmitry A. Kazakov
2018-03-29 15:39       ` Jeffrey R. Carter
2018-04-15  5:20         ` reinert
2018-03-29 22:33 ` Shark8
2018-03-30  9:04   ` Dmitry A. Kazakov
2018-03-30 20:46     ` Paul Rubin
2018-03-31  0:09       ` Randy Brukardt
2018-03-31  6:00         ` Paul Rubin
2018-03-31  9:37           ` Jacob Sparre Andersen
2018-03-31 10:44             ` Dmitry A. Kazakov
2018-04-02  3:35           ` Randy Brukardt
2018-04-02  6:23     ` alby.gamper
2018-04-02  7:12       ` alby.gamper [this message]
2018-04-05 14:07       ` Brad Moore
2018-04-05 15:09         ` Dmitry A. Kazakov
2018-04-07  4:16           ` Brad Moore
2018-04-05 15:30         ` Jeffrey R. Carter
2018-04-05 19:33           ` Spiros Bousbouras
2018-04-05 19:44           ` Simon Wright
2018-04-05 20:25             ` Jeffrey R. Carter
2018-04-06  5:58         ` Benchmarks Game: Thread ring (Was: Large number of tasks slows down my program (using debian) - any fix?) Jacob Sparre Andersen
2018-04-07  4:28           ` Brad Moore
2018-04-06 15:48         ` Large number of tasks slows down my program (using debian) - any fix? Jeffrey R. Carter
2018-04-07  4:39           ` Brad Moore
2018-04-07  8:15             ` Jeffrey R. Carter
2018-04-07 16:28               ` Brad Moore
2018-04-07 18:41                 ` Jeffrey R. Carter
2018-04-08  0:29                   ` Brad Moore
2018-04-08  8:25                     ` Jeffrey R. Carter
2018-04-08  0:06                 ` Robert I. Eachus
2018-04-07 16:51               ` Brad Moore
2018-04-07 12:21         ` Simon Wright
2018-04-07 16:57           ` Brad Moore
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox