Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to use a connection pool when using SQLite in Serialized mode?

I am a newbie for SQLite and I have read that the Serialized mode of SQLite is thread-safe, and can be safely used by multiple threads with no restriction.

My question is: In a single-threaded app, is there any performance impact if I use one same global connection for all database operation comparing to using one connection per database operation?(Ignore the performance impact for building db connection)

To be specific, imagine such a scenario: in the same thread, I need build two prepared statement to query two table respectively in the same dababase, and I need use STEP() to retrieve data from the two statement alternatively. My question is which will have better performance: I. Using one same connection for both statement; II. one connection per statement?(not account for the performance impact occurred in the process of building connection) Or is it necessary to use a connection pool for performance benefit?

like image 783
SimonFisher Avatar asked Oct 22 '13 02:10

SimonFisher


People also ask

When should you not use connection pooling?

You reuse a prior database connection, in a new context to avoid the cost of setting up a new database connection for each request. The primary reason to avoid using database connections is that you're application's approach to solving problems isn't structured to accommodate a database connection pool.

Does SQLite support connection pooling?

Connection PoolingThe underlying, native SQLite connections are now pooled by default. This greatly improves the performance of opening and closing connections.

Why is connection pooling required?

Using connection pools helps to both alleviate connection management overhead and decrease development tasks for data access. Each time an application attempts to access a backend store (such as a database), it requires resources to create, maintain, and release a connection to that datastore.

What is the use of connection pooling in SQL?

A connection pool is created for each unique connection string. When a pool is created, multiple connection objects are created and added to the pool so that the minimum pool size requirement is satisfied. Connections are added to the pool as needed, up to the maximum pool size specified (100 is the default).


1 Answers

In a single-threaded app, you can use either a single or multiple connections. In the latter case, it is possible to run multiple queries in parallel.

Please note that there is one transaction per connection. If you have multiple connections, one writer will block all readers.

like image 175
CL. Avatar answered Oct 15 '22 13:10

CL.