On Performance.MaxBackgroundThreads vs Performance.MaxThreads  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by zarkogajic »

Hi Support,

Re (indirectly related): https://forum.pdf-xchange.com/viewtopic.php?f=66&t=33528&p=141379&hilit=MaxBackgroundThreads#p141379

I'm using AsyncDo to process my custom IOperations. Say I have 50 IOperations. Setting "Performance.MaxBackgroundThreads" = 2 -> I would expect all 50 IOperations are executed within same two threads.

However, that is not the case. The number of threads is 4 (so all 50 operations are done by 4 threads). This number "4" is not related to the number of physical cores my machine has. I have the same result on a 4(/8) cores machine and on a 10(/20) cores machine.

Only when I raise MaxBackgroundThreads to a value greater than 4 - the number of reported threads will be as set.

The number of threads actually used seems to be related to "Performance.MaxThreads" - which by default is 0.

When Performance.MaxThreads is 0 (default), setting Performance.MaxBackgroundThreads to any value from 1-4 would always result in 4 threads being used. Raising that value raises the actual number of threads used.

When I set Performance.MaxThreads = 1 or 2, then the number of threads (by AsyncDo) is always 2, nevermind what I set for Performance.MaxBackgroundThreads.

When I set Performance.MaxThreads = 3 or 4, then the number of threads (by AsyncDo) is always 3 or 4, nevermind what I set for Performance.MaxBackgroundThreads.

When I set Performance.MaxThreads = 8, then the number of threads (by AsyncDo) is always at least 4, nevermind what I set for Performance.MaxBackgroundThreads.


[Q]: please clearly explain how Performance.MaxThreads and Performance.MaxBackgroundThreads are related, and how can I be in full control of the number of threads used by AsyncDo?

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

We'll need Vasyl to reply to this one because there is complex behavior coded into this logic. Sadly he does not have enough time for this as we are preparing for the V9 that should be out till the end of the month if everything goes well. Please bump this topic when the V9 is out.
Meanwhile, use the results from your investigation as given - I've seen the code - it's made that way. Why - we'll see later.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by zarkogajic »

Deal :)

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by zarkogajic »

Hi,

Since v9 is out (and I do know you have a lot of tasks on your hands :)) - pinging in here...

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Vasyl-Tracker Dev Team »

Hi Zarko.

The reason of that is simple: the AsyncDo() uses its own narrowed 'room' in our multithreading system. And at the moment this room is limited to 4 max simultaneously working threads.

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by zarkogajic »

Hi Vasly,
at the moment this room is limited to 4 max simultaneously working threads.
Thanks.

But, "when I set MaxBackgroundThreads to a value greater than 4 - the number of reported threads will be as set (so more than 4).".


-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Vasyl-Tracker Dev Team »

Sorry, missed that you change the MaxBackgroundThreads. Yes, this parameter is for SDK and actually is calculated as:

Code: Select all

maxBackgroundThreads = min(   Performance.MaxThreads, 
                              max(Performance.MaxBackgroundThreads, 4)
                          );

And Performance.MaxThreads=0 == "The number of logical processors"
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by zarkogajic »

Hi Vasyl,

Is there a way I could force, for example, only 1 thread to be used by AsyncDo (via Performance.MaxThreads / Performance.MaxBackgroundThreads) ?

p.s.
When I set Performance.MaxThreads = 1 or 2, then the number of threads (by AsyncDo) is always 2, nevermind what I set for Performance.MaxBackgroundThreads.


-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Vasyl-Tracker Dev Team »

Sorry, no way to do it at the moment.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: On Performance.MaxBackgroundThreads vs Performance.MaxThreads  SOLVED

Post by zarkogajic »

Hi Vasyl,

Ok, thanks.

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17910
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

On Performance.MaxBackgroundThreads vs Performance.MaxThreads

Post by Tracker Supp-Stefan »

:)
Post Reply