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:2f41:: with SMTP id j62-v6mr5673464itj.19.1522650221909; Sun, 01 Apr 2018 23:23:41 -0700 (PDT) X-Received: by 2002:a9d:16c3:: with SMTP id s3-v6mr473106ots.13.1522650221794; Sun, 01 Apr 2018 23:23:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!k65-v6no1929602ita.0!news-out.google.com!u64-v6ni4817itb.0!nntp.google.com!k65-v6no1929598ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 1 Apr 2018 23:23:41 -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: 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 06:23:41 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:51291 Date: 2018-04-01T23:23:41-07:00 List-Id: 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;