Subject Re: Issue for process
Author heroes3lover
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@...> wrote:
>
> --- In firebird-support@yahoogroups.com, "heroes3lover"
> <heroes3lover@> wrote:
> >
> > I have finished code to use multithread to access firebird,
> > but not satified with the testing result.
> > Is there any settings I should pay attention?
> >
> > Thanks,
> > Roc
> >
>
> From my prior post:
>
> ---
> Use OutputDebugString in the windows unit to send messages from
within
> your thread. Download DebugView from Microsoft (formerly
sysinternals)
> and you can watch what is happenning. You are doing synchronise to
> write your logs at the moment, which is going to put a bottle neck
in
> there.
> ---
>
> Your logging mechanism is a massive bottleneck. You are not going to
> get good performance while you have all those synchronise calls.
Every
> time you synchronise, your thread has to wait for the main thread to
> wake up, process its message queue, then sleep again.
>
> Either write your own threadsafe logging queue that can buffer the
log
> messages without holding up your threads, or do what I suggested and
> replace your Synchronise calls to OutputDebugString calls and let
> Windows take care of it.
>
> Once you have eliminated that as a problem, you can then move onto
> what resource is actually being thrashed or underutilised, playing
> around with cache sizes etc.
>
> Adam
>


Thanks Adam,
I know Synchronize will suspend thread, all of the code before
query.open is pretty simple, it will not take main process lots of
time, and I just need the queyr.open to be multithread, I hope this
can save database access time, code below:

procedure TReportSQLCompleteDSPlusThread.Execute;
begin
Try
Synchronize(IncCounter);
if isSelectSQL then
qryInThread.Open
else
qryInThread.Execute;
WaitForSingleObject(hMutex,INFINITE);
Synchronize(MaintProc);
Except
end;
Synchronize(ReduceCounter);
ReleaseMutex(hMutex);
Terminate;
end;

It's simple code, I create almost 8 threads, each thread has its owner
connection and TSQLQuery, you can see Synchronize(IncCounter); it is
pretty simple, which just increase the counter.
MaintProc is refreshing the global things by main process, but from
the testing result, it does not look like all the SQL has
finished,and waiting for refreshing.


best regards,
Roc