From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:2105:: with SMTP id e5-v6mr5508972ita.55.1522653122620; Mon, 02 Apr 2018 00:12:02 -0700 (PDT) X-Received: by 2002:a9d:e5b:: with SMTP id n27-v6mr480222otd.2.1522653122519; Mon, 02 Apr 2018 00:12:02 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u184-v6no3751745ita.0!news-out.google.com!u64-v6ni4817itb.0!nntp.google.com!k65-v6no1958425ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 2 Apr 2018 00:12:02 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=101.164.108.182; posting-account=wavAeAoAAAAZF_sXSZepBukuPCBO0Zqt NNTP-Posting-Host: 101.164.108.182 References: <1aa8f536-250d-4bef-9392-4d936f916e5f@googlegroups.com> <9377f941-31d0-4260-818a-8e189aac8c19@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <48c85281-e18f-419f-b498-e87d60d28173@googlegroups.com> Subject: Re: Large number of tasks slows down my program (using debian) - any fix? From: alby.gamper@gmail.com Injection-Date: Mon, 02 Apr 2018 07:12:02 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:51292 Date: 2018-04-02T00:12:02-07:00 List-Id: 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