|
|
Home » Developing U++ » UppHub » Job package: A lightweight worker thread for non-blocking operations. (A)
Re: RE: Job package: A scope-bound worker thread for non-blocking operations. [message #48791 is a reply to message #48790] |
Tue, 19 September 2017 10:12 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Small issues with the code:
sData template does not compile with MSC (I believe it is not legit C++ code, probably GCC eats it but it is not OK). Replaced by
template<class T>
One<T>*& sData()
{
static thread_local One<T>* sData = NULL;
return sData;
}
GetNewWorkerId has int64 internal counter (which IMO is reasonable), but the rest of the code is using int.
Anyway, as you are using "TIMING", it appears you are benchmarking in debug mode. I have done some changes:
#include <Core/Core.h>
#include <Job/Job.h>
using namespace Upp;
String GetDivisors()
{
String s;
int number = (int) 1000;
Vector<int> divisors;
for(auto i = 1, j = 0; i < number + 1; i++) {
auto d = number % i;
if(d == 0){
divisors.Add(i);
j++;
}
if(i == number)
s = Format("Worker Id: %d, Number: %d, Divisors (count: %d): %s",
GetWorkerId(),
number,
j,
divisors.ToString());
}
return pick(s);
}
// #define OUTPUT
#define N 100000
CONSOLE_APP_MAIN
{
Array<Job<String>> jobs;
jobs.SetCount(CPU_Cores() + 2);
CoWork cowork;
// cowork.SetPoolSize(CPU_Cores() + 2);
Vector<String> results;
RDUMP(CPU_Cores());
{
RTIMING("CoWork -- With stdout output");
for(int i = 0; i < N; i++)
cowork & [=, &results] { String h = GetDivisors(); CoWork::FinLock(); results.At(i) = h; };
cowork.Finish();
// Stdout output section.
#ifdef OUTPUT
for(auto& r : results)
Cout() << r << '\n';
#endif
}
{
RTIMING("Job -- With stdout output");
int i = 0;
while(i < N) {
for(auto& job : jobs) {
if(!job.IsFinished()) {
continue;
}
job & [=]{ Job<String>::Data() = GetDivisors(); };
if(!(~job).IsEmpty()) {
#ifdef OUTPUT
Cout() << ~job << '\n';
#endif
if(++i == N) break;
}
}
}
}
}
with results in _RELEASE_ mode:
* d:\upp.out\MyApps\MSC15\JobBenchmark.exe 19.09.2017 10:01:27, user: cxl
CPU_Cores() = 8
TIMING Job -- With stdout output: 123.00 ms - 123.00 ms (123.00 ms / 1 ), min: 123.00 ms, max: 123.00 ms, nesting: 1 - 1
TIMING CoWork -- With stdout output: 103.00 ms - 103.00 ms (103.00 ms / 1 ), min: 103.00 ms, max: 103.00 ms, nesting: 1 - 1
Now I fully understand that performance is not the reason for Job, but as I have seen no technical reasons why CoWork should be that much slower, I had to check....
|
|
|
|
|
Job package: A lightweight worker thread for non-blocking operations.
By: Oblivion on Sun, 10 September 2017 12:29
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 15:08
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 15:56
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 17:05
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 19:08
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 20:13
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 21:16
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Mon, 11 September 2017 00:06
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Mon, 11 September 2017 00:25
|
|
|
RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sun, 17 September 2017 23:20
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Mon, 18 September 2017 08:23
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Mon, 18 September 2017 08:29
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 00:01
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 08:37
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 08:53
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:12
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 08:12
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:15
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:24
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 11:12
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 12:31
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 13:01
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 23 September 2017 14:17
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 07 October 2017 15:03
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Sat, 07 October 2017 15:51
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 07 October 2017 16:04
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sun, 08 October 2017 15:01
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 11:51
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 10 October 2017 16:10
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 17:02
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 10 October 2017 20:51
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 23:48
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 09:23
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 09:42
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 09:47
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 09:50
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 19:30
|
|
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 20:14
|
|
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 20:09
|
Goto Forum:
Current Time: Wed May 01 19:09:40 CEST 2024
Total time taken to generate the page: 0.02693 seconds
|
|
|