views:

472

answers:

8

I tried sqlite, by using multi-thread, only one thread can update db at the same time.. I need multi-thread updating the db at same time. Is there are any DB can do the job?

ps: I use delphi6.


I found that sqlite can support multi-threading,

But in my test of asgsqlite, when one thread inserting, others will fail to insert.

I'm still in testing.

+7  A: 

SQLite can be used in multi-threaded environments.

Check out this link.

Yuval A
looks like sqlite support multi-threading..
linjunhalida
But they don't encourage it.
jeffamaphone
+1  A: 

since version 3.3.1, SQLite's threading requirements have been greatly relaxed. in most cases, it means that it simply works. if you really need more concurrency than that, it might be better to use a DB server.

Javier
+1  A: 

SQL Server 2008 Express supports concurrency, as well as most other features of SQL Server. And it's free.

John Saunders
AFAIK it will only use one CPU for all the SPIDs, but it will happily support concurrent SPIDs...
Marc Gravell
+4  A: 

Firebird can be used in an embedded version, but it's no problem to use the standard (server) installation locally as well. Very small, easy to deploy, concurrent access. Works good with Delphi, you should look into it as an option.

See also the StackOverflow question "Which embedded database to use in a Delphi application?"

mghie
+1  A: 

Why do you need multiple threads to update it at the same time? I'm sure sqlite will ensure that the updates get done correctly, even if that means one thread waiting for the other one to finish; this is transparent to the application.

Indeed, having several threads updating concurrently would, in all likelihood, not be beneficial to performance. That's to say, it might LOOK like several threads were updating concurrently, but actually the result would be that the updates get done slower than if they weren't (due to the fact that they need to hold many page locks etc to avoid problems).

MarkR
That assumes that all threads are updating the same records or at least the same table. Even then there are other DB engines that allow fast multi-threaded updates, like Firebird.
mghie
I use multi-threading for distinguish operations , like one threading reading data,one threading process data.
linjunhalida
+1  A: 

DBISAM from ElevateSoft works very nicely in multi-threaded mode, and has auto-session naming to make this easy. Be sure to follow the page in the help on how to make it all safe, and job done.

mj2008
A: 

I'm actually at the moment doing performance testing with a multi-threaded Java process on Sybase ASE. The process parses a 1GB file and does inserts into a table.

I was afraid at first, because many of the senior programmers warned me about "table locking" and how dangerous it is to do concurrent access to DB. But I went ahead and did testing (because I wanted to find out for myself).

I created and compared a single threaded process to a process using 4 threads. I only received a 20% reduction in total execution time. I retried the the process using different thread counts and batch insert sizes. The maximum I could squeeze was 20%.

We are going to be switching to Oracle soon, so I'll share how Oracle handles concurrent inserts when that happens.

Jose Chavez
+1  A: 

Sqlite locks the entire database when updating (unless this has changed since I last used it). A second thread cannot update the database at the same time (even using entirely separate tables). However there is a timeout parameter that tells the second thread to retry for x milliseconds before failing. I think ASqlite surfaces this parameter in the database component (I think I actually wrote that bit of code, all 3 lines, but it was a couple of years ago).

Setting the timeout to a larger value than 0 will allow multiple threads to update the database. However there may be performance implications.

SeanX