Board index » delphi » Re: timeout in clientsocket.sendtext?

Re: timeout in clientsocket.sendtext?


2005-02-26 05:10:51 AM
delphi282
The size of my ThreadCacheSize is set to 1000. is it too high (we use have
1 GB of memory).
I can move the DBcode to the OnClientExecute without any problem. With
thread pooling, if I create my tables in on ClientExecute, do you think the
seversocket will reuse the tables (without recreating them) for the next
thread?
Thanks,
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Halim" <XXXX@XXXXX.COM>writes
news:421f7aa0$XXXX@XXXXX.COM...

>Does the pooling works with the ClientExecute thread only or
>does it work on every thread involved in handling the socket.

There is only one thread handling the socket. TServerSocket automatically
checks the pool first for available threads before triggering the
OnGetThread event. OnGetThread is only triggered when no pooled threads
are
available. When the client disconnects, the thread is automatically
placed
into the pool if there is space available, otherwise the thread is
terminated.

>this is what takes a longtime and CPU. I call it when I create the thread
>(it consumes CPU up to 40% per connection) right before the
>Clientexecute.
>it will open a DBsession with tables and stuff.

What is the value of your server's ThreadCacheSize property? It is set to
10 by default. Have you tried increasing it?

>ThreadDataBase.Open;

You are opening the database in the context of OnGetThread, and thus in
the
context of the thread that the server itself runs in, not in the context
of
the client thread. What happens if you move your database code into
ClientExecute() instead?


Gambit


 
 

Re: timeout in clientsocket.sendtext?

"Halim" <XXXX@XXXXX.COM>writes
Quote
With thread pooling, if I create my tables in on ClientExecute,
do you think the seversocket will reuse the tables (without
recreating them) for the next thread?
ClientExecute() is executed each time a new client connects, so your DB code
will be executed multiple times. If you want to ensure that your DB code is
only called one per thread, override the thread's Execute() method, making
sure to call the base class Execute() after you are done so that you still
have pooling support. For example:
constructor TFileServerThread.Create(XSuspend: Boolean; XSocket:
TServerclientWinSocket);
begin
inherited Create(XSuspend, XSocket);
end;
procedure TFileServerThread.Execute;
begin
try
// initialize the DB stuff here...
except
on E: Exception do
begin
SendMessage(MainForm.ListBox1.Handle, LB_INSERTSTRING, 0,
Integer(PChar(DateTimeToStr(Now) + ': Error 00013 :' +
E.Message)));
HandleException;
KeepInCache := False;
Exit;
end;
end;
inherited;
end;
procedure TFileServerThread.DoTerminate;
begin
// cleanup the db stuff here...
inherited;
end;
procedure TFileServerThread.ClientExecute;
begin
// socket related code here...
end;
Gambit
 

Re: timeout in clientsocket.sendtext?

Thanks Remy,
I think the way the app works is to refresh the database everytime a new
client connects. I don't think I can use the DB stuff in thread pooling. I
have to recreate the entire data session every connection. Do you think 1000
for thread cache size is ok?
I will have to split the data depending on the connection type. some
connections require 4 tables only, instead of 9 + queries. Doing so, I
should be able to speed up the process.
I have another question, you have seen most everything about my code. I
don't know why it does not work on more than one processor machines. it
crashes within minutes.
I found out that if we use it on a multiprocessor machine, each client
connection could be handled by more than one thread. the server crashes at
the end.
do you know anything about this issue?
Thanks,
Halim.
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Halim" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>With thread pooling, if I create my tables in on ClientExecute,
>do you think the seversocket will reuse the tables (without
>recreating them) for the next thread?

ClientExecute() is executed each time a new client connects, so your DB
code
will be executed multiple times. If you want to ensure that your DB code
is
only called one per thread, override the thread's Execute() method, making
sure to call the base class Execute() after you are done so that you still
have pooling support. For example:

constructor TFileServerThread.Create(XSuspend: Boolean; XSocket:
TServerclientWinSocket);
begin
inherited Create(XSuspend, XSocket);
end;

procedure TFileServerThread.Execute;
begin
try
// initialize the DB stuff here...
except
on E: Exception do
begin
SendMessage(MainForm.ListBox1.Handle, LB_INSERTSTRING, 0,
Integer(PChar(DateTimeToStr(Now) + ': Error 00013 :' +
E.Message)));
HandleException;
KeepInCache := False;
Exit;
end;
end;
inherited;
end;

procedure TFileServerThread.DoTerminate;
begin
// cleanup the db stuff here...
inherited;
end;

procedure TFileServerThread.ClientExecute;
begin
// socket related code here...
end;


Gambit


 

Re: timeout in clientsocket.sendtext?

"Halim" <XXXX@XXXXX.COM>writes
Quote
I don't know why it does not work on more than one processor
machines. it crashes within minutes. I found out that if we use it
on a multiprocessor machine, each client connection could be
handled by more than one thread. the server crashes at the end.
Each connection would still be handled by one thread at a time. The
connection is tied to a thread, and a thread is tied to a particular
processor. M guess would be that your code is not properly thread-safe, so
muliple threads are trying to access the same resources at exactly the same
time. Always protect shared resources with proper synchronizing, regardless
of whether the threads are running on the same processor or different
procesors.
Gambit