On 11/23/07, Sabyasachi Ruj <[EMAIL PROTECTED]> wrote:

> I have an application that uses SQLite extensively.
> In a part of that application, I need to do the following steps:-
>         1. I need to create a thread per request basis.
>         2. Open SQLite connection.
>         3. Then retrieve data from SQLite and do some calculation.
>         4. Construct the result and send.
>         5. Then close SQLite connection.
>
> This type of threads are being created very frequently.
> And thats the reason my application is becoming very CPU hungry.

> The following ideas came in my mind:-
>         1. I can share open one SQLite connection and share the connection
>         between threads with PROPER MANUAL synchronization (so that only one
>         thread uses the connection at a time).
>                 => This I ruled out because it will introduce unnecessary 
> waiting.
>
>         2. Create a pool of SQLite connections and allocate them the threads 
> on demand
>         basis.
>                 => This is still in 'idea' phase.
>                 I want to avoid the complexity that it will introduce in the 
> application.
>
> Is there any way by which I can optimize my application?

That's really going to depend on what your application actually does.
In general, for a high efficiency application the goal is to have
exactly one thread per logical CPU running at any given time.  You
don't want 100 threads trying to run at the same time just because you
have 100 users active at the moment.

The most straightforward approach is to find the number of CPUs,
create N worker threads (maybe a few more depending on I/O vs CPU
distribution), keep an open sqlite connection in each one, and have
them wait on a single queue for requests to answer.  Your main thread
will only be a manager, setting up requests and placing them on the
queue, throttling requests to prevent backlog, etc.

There is necessarily some complexity in this approach.  What platform
is this for?

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to