Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #2265 > unrolled thread
| Started by | "aminer" <aminer@videotron.ca> |
|---|---|
| First post | 2012-10-01 11:51 -0500 |
| Last post | 2012-10-01 12:43 -0500 |
| Articles | 7 — 1 participant |
Back to article view | Back to comp.programming
My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 11:51 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 11:54 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 12:06 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 12:18 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 12:30 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 12:36 -0500
Re: My threadpool engine and scalability... "aminer" <aminer@videotron.ca> - 2012-10-01 12:43 -0500
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 11:51 -0500 |
| Subject | My threadpool engine and scalability... |
| Message-ID | <k4ce5t$cv8$5@dont-email.me> |
Hello,
If you take a look at my threadpool engine:
http://pages.videotron.com/aminer/
you will notice that it does not scale in the execute() method
cause LockedIncLong(balance1) is expensive.
here is the execute method:
==
function TThreadPool.execute(func:TMyProc;const Context: Pointer): Boolean;
var
local_balance,local_count:long;
params: PParams;
p:pointer;
begin
new(params);
setlength(params^,1);
params^[0].proc:=func;
params^[0].data:=context;
local_balance:=LockedIncLong(balance1) mod FThreadCount;
while not Queues[local_balance].push(tobject(params)) do sleep(0);
events[local_balance].setevent;
end;
===
Now to be able to scale the execute() method we have to add a getindex()
method like this
function TThreadPool.getindex(var index:long);
begin
if index <> 0
then
begin
inc(index);
index:=index mod FThreadCount;
end;
end;
and also add an execute1() method that scales perfectly like this:
==
function TThreadPool.execute1(func:TMyProc;const Context:
Pointer;index:long): Boolean;
var
local_balance,local_count:long;
params: PParams;
p:pointer;
begin
new(params);
setlength(params^,1);
params^[0].proc:=func;
params^[0].data:=context;
while not Queues[index].push(tobject(params)) do sleep(0);
events[local_balance].setevent;
end;
==
so we have to call the getindex() method from mutiple threads like this:
// we have to initialize count to zero before:
getindex(count)
ThreadPool.execute(myproc,data,count)
and now the execute1() method will scale perfectly.
I will try update my threadpol engine soon.
Thank you,
Amine Moulay Ramdane.
[toc] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 11:54 -0500 |
| Message-ID | <k4cec8$ech$1@dont-email.me> |
| In reply to | #2265 |
Sorry i correct a mistake, getindex() method has to be wrote like this
function TThreadPool.getindex(var index:long);
begin
if index = 0
then
begin
inc(index);
index:=index mod FThreadCount;
end;
end;
Amine Moulay Ramdane.
"aminer" <aminer@videotron.ca> wrote in message
news:k4ce5t$cv8$5@dont-email.me...
>
> Hello,
>
> If you take a look at my threadpool engine:
>
> http://pages.videotron.com/aminer/
>
> you will notice that it does not scale in the execute() method
> cause LockedIncLong(balance1) is expensive.
>
> here is the execute method:
>
> ==
>
> function TThreadPool.execute(func:TMyProc;const Context: Pointer):
> Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> local_balance:=LockedIncLong(balance1) mod FThreadCount;
> while not Queues[local_balance].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ===
>
> Now to be able to scale the execute() method we have to add a getindex()
> method like this
>
> function TThreadPool.getindex(var index:long);
> begin
> if index <> 0
> then
> begin
> inc(index);
> index:=index mod FThreadCount;
> end;
> end;
>
>
> and also add an execute1() method that scales perfectly like this:
>
> ==
> function TThreadPool.execute1(func:TMyProc;const Context:
> Pointer;index:long): Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> while not Queues[index].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ==
>
> so we have to call the getindex() method from mutiple threads like this:
>
> // we have to initialize count to zero before:
>
> getindex(count)
> ThreadPool.execute(myproc,data,count)
>
> and now the execute1() method will scale perfectly.
>
>
> I will try update my threadpol engine soon.
>
>
>
> Thank you,
> Amine Moulay Ramdane.
>
>
>
>
>
>
>
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 12:06 -0500 |
| Message-ID | <k4cf2v$ja2$1@dont-email.me> |
| In reply to | #2265 |
After adding getindex() and execute1() methods , this threadpool engine can also be used as a scalable queue (not a strict FIFO queue, but it's also useful), . Amine Moulay Ramdane "aminer" <aminer@videotron.ca> wrote in message news:k4ce5t$cv8$5@dont-email.me... > > Hello, > > If you take a look at my threadpool engine: > > http://pages.videotron.com/aminer/ > > you will notice that it does not scale in the execute() method > cause LockedIncLong(balance1) is expensive. > > here is the execute method: > > == > > function TThreadPool.execute(func:TMyProc;const Context: Pointer): > Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > local_balance:=LockedIncLong(balance1) mod FThreadCount; > while not Queues[local_balance].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > === > > Now to be able to scale the execute() method we have to add a getindex() > method like this > > function TThreadPool.getindex(var index:long); > begin > if index <> 0 > then > begin > inc(index); > index:=index mod FThreadCount; > end; > end; > > > and also add an execute1() method that scales perfectly like this: > > == > function TThreadPool.execute1(func:TMyProc;const Context: > Pointer;index:long): Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > while not Queues[index].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > == > > so we have to call the getindex() method from mutiple threads like this: > > // we have to initialize count to zero before: > > getindex(count) > ThreadPool.execute(myproc,data,count) > > and now the execute1() method will scale perfectly. > > > I will try update my threadpol engine soon. > > > > Thank you, > Amine Moulay Ramdane. > > > > > > > > > >
[toc] | [prev] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 12:18 -0500 |
| Message-ID | <k4cfok$nuq$1@dont-email.me> |
| In reply to | #2265 |
I mean this threadpool engine will become scalable, causei am using mutiple lockfree FIFO queues , so that there is less contention and using work-stealing also, so after adding getindex() and execute1() methods , this threadpool engine will become scalable. this threadpool engine can also be used as a scalable queue (not a strict FIFO queue, but it's also useful). This threadpool engine is useful and that is what's important. . Amine Moulay Ramdane "aminer" <aminer@videotron.ca> wrote in message news:k4ce5t$cv8$5@dont-email.me... > > Hello, > > If you take a look at my threadpool engine: > > http://pages.videotron.com/aminer/ > > you will notice that it does not scale in the execute() method > cause LockedIncLong(balance1) is expensive. > > here is the execute method: > > == > > function TThreadPool.execute(func:TMyProc;const Context: Pointer): > Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > local_balance:=LockedIncLong(balance1) mod FThreadCount; > while not Queues[local_balance].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > === > > Now to be able to scale the execute() method we have to add a getindex() > method like this > > function TThreadPool.getindex(var index:long); > begin > if index <> 0 > then > begin > inc(index); > index:=index mod FThreadCount; > end; > end; > > > and also add an execute1() method that scales perfectly like this: > > == > function TThreadPool.execute1(func:TMyProc;const Context: > Pointer;index:long): Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > while not Queues[index].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > == > > so we have to call the getindex() method from mutiple threads like this: > > // we have to initialize count to zero before: > > getindex(count) > ThreadPool.execute(myproc,data,count) > > and now the execute1() method will scale perfectly. > > > I will try update my threadpol engine soon. > > > > Thank you, > Amine Moulay Ramdane. > > > > > > > > > >
[toc] | [prev] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 12:30 -0500 |
| Message-ID | <k4cgfo$sp6$1@dont-email.me> |
| In reply to | #2265 |
Hello,
Of course i can change and simplify the interface of my threadpool engine
so there will be no getindex() method just an execute1() method like this
==
function TThreadPool.execute1(func:TMyProc;const Context:
Pointer;index:long): Boolean;
var
local_balance,local_count:long;
params: PParams;
p:pointer;
begin
new(params);
setlength(params^,1);
params^[0].proc:=func;
params^[0].data:=context;
if index = 0
then
begin
inc(index);
index:=index mod FThreadCount;
end;
while not Queues[index].push(tobject(params)) do sleep(0);
events[local_balance].setevent;
end;
=
Amine Moulay Ramdane.
"aminer" <aminer@videotron.ca> wrote in message
news:k4ce5t$cv8$5@dont-email.me...
>
> Hello,
>
> If you take a look at my threadpool engine:
>
> http://pages.videotron.com/aminer/
>
> you will notice that it does not scale in the execute() method
> cause LockedIncLong(balance1) is expensive.
>
> here is the execute method:
>
> ==
>
> function TThreadPool.execute(func:TMyProc;const Context: Pointer):
> Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> local_balance:=LockedIncLong(balance1) mod FThreadCount;
> while not Queues[local_balance].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ===
>
> Now to be able to scale the execute() method we have to add a getindex()
> method like this
>
> function TThreadPool.getindex(var index:long);
> begin
> if index <> 0
> then
> begin
> inc(index);
> index:=index mod FThreadCount;
> end;
> end;
>
>
> and also add an execute1() method that scales perfectly like this:
>
> ==
> function TThreadPool.execute1(func:TMyProc;const Context:
> Pointer;index:long): Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> while not Queues[index].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ==
>
> so we have to call the getindex() method from mutiple threads like this:
>
> // we have to initialize count to zero before:
>
> getindex(count)
> ThreadPool.execute(myproc,data,count)
>
> and now the execute1() method will scale perfectly.
>
>
> I will try update my threadpol engine soon.
>
>
>
> Thank you,
> Amine Moulay Ramdane.
>
>
>
>
>
>
>
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 12:36 -0500 |
| Message-ID | <k4cgqj$v06$1@dont-email.me> |
| In reply to | #2265 |
Hello,
I have corrected a mistake in execute1() method , here it is again:
==
function TThreadPool.execute1(func:TMyProc;const Context:
Pointer;index:long): Boolean;
params: PParams;
p:pointer;
begin
new(params);
setlength(params^,1);
params^[0].proc:=func;
params^[0].data:=context;
if index = 0
then
begin
inc(index);
index:=index mod FThreadCount;
end;
while not Queues[index].push(tobject(params)) do sleep(0);
events[index].setevent;
end;
=
Amine Moulay Ramdane.
"aminer" <aminer@videotron.ca> wrote in message
news:k4ce5t$cv8$5@dont-email.me...
>
> Hello,
>
> If you take a look at my threadpool engine:
>
> http://pages.videotron.com/aminer/
>
> you will notice that it does not scale in the execute() method
> cause LockedIncLong(balance1) is expensive.
>
> here is the execute method:
>
> ==
>
> function TThreadPool.execute(func:TMyProc;const Context: Pointer):
> Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> local_balance:=LockedIncLong(balance1) mod FThreadCount;
> while not Queues[local_balance].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ===
>
> Now to be able to scale the execute() method we have to add a getindex()
> method like this
>
> function TThreadPool.getindex(var index:long);
> begin
> if index <> 0
> then
> begin
> inc(index);
> index:=index mod FThreadCount;
> end;
> end;
>
>
> and also add an execute1() method that scales perfectly like this:
>
> ==
> function TThreadPool.execute1(func:TMyProc;const Context:
> Pointer;index:long): Boolean;
>
> var
> local_balance,local_count:long;
>
> params: PParams;
> p:pointer;
>
> begin
> new(params);
> setlength(params^,1);
> params^[0].proc:=func;
> params^[0].data:=context;
>
> while not Queues[index].push(tobject(params)) do sleep(0);
> events[local_balance].setevent;
> end;
>
> ==
>
> so we have to call the getindex() method from mutiple threads like this:
>
> // we have to initialize count to zero before:
>
> getindex(count)
> ThreadPool.execute(myproc,data,count)
>
> and now the execute1() method will scale perfectly.
>
>
> I will try update my threadpol engine soon.
>
>
>
> Thank you,
> Amine Moulay Ramdane.
>
>
>
>
>
>
>
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | "aminer" <aminer@videotron.ca> |
|---|---|
| Date | 2012-10-01 12:43 -0500 |
| Message-ID | <k4ch8a$23o$1@dont-email.me> |
| In reply to | #2265 |
Hello, Sorry here is the final execute1() method, no need for getindex(), i have to use LockedIncLong() but it will be called only once: == function TThreadPool.execute1(func:TMyProc;const Context: Pointer;index:long): Boolean; params: PParams; p:pointer; begin new(params); setlength(params^,1); params^[0].proc:=func; params^[0].data:=context; if index = 0 then begin index:=LockedIncLong(balance1) mod FThreadCount; end; while not Queues[index].push(tobject(params)) do sleep(0); events[index].setevent; end; = Thank you, Amine Moulay Ramdane. "aminer" <aminer@videotron.ca> wrote in message news:k4ce5t$cv8$5@dont-email.me... > > Hello, > > If you take a look at my threadpool engine: > > http://pages.videotron.com/aminer/ > > you will notice that it does not scale in the execute() method > cause LockedIncLong(balance1) is expensive. > > here is the execute method: > > == > > function TThreadPool.execute(func:TMyProc;const Context: Pointer): > Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > local_balance:=LockedIncLong(balance1) mod FThreadCount; > while not Queues[local_balance].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > === > > Now to be able to scale the execute() method we have to add a getindex() > method like this > > function TThreadPool.getindex(var index:long); > begin > if index <> 0 > then > begin > inc(index); > index:=index mod FThreadCount; > end; > end; > > > and also add an execute1() method that scales perfectly like this: > > == > function TThreadPool.execute1(func:TMyProc;const Context: > Pointer;index:long): Boolean; > > var > local_balance,local_count:long; > > params: PParams; > p:pointer; > > begin > new(params); > setlength(params^,1); > params^[0].proc:=func; > params^[0].data:=context; > > while not Queues[index].push(tobject(params)) do sleep(0); > events[local_balance].setevent; > end; > > == > > so we have to call the getindex() method from mutiple threads like this: > > // we have to initialize count to zero before: > > getindex(count) > ThreadPool.execute(myproc,data,count) > > and now the execute1() method will scale perfectly. > > > I will try update my threadpol engine soon. > > > > Thank you, > Amine Moulay Ramdane. > > > > > > > > > >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.programming
csiph-web