Reputation: 259
I have Windows Form application.
(C# with visual studio 2010, Framework : 4.0)
Database: .db (file database), connection object through SQLite
Thread th = new Thread(() => database(node, xNodetcname, xNodesqlquery1, xNodeHint, e, inXml));
th.Name = thread;
th.Start();
Above code create each thread and processing parallel on database()
function.
Each thread having one SQL Query which fetching data from database.
While I not use Multithreading the performance is better but when I use Multithreading the performance is down.
Example:
Without Multithreading 3 query processing time = 1.5 minutes
With Multithreading 3 query processing time = 1.9 minutes.
My aim is to reduce the processing time of query.
Upvotes: 0
Views: 974
Reputation: 3447
There are a few things you have to take into consideration here:
Upvotes: 2
Reputation: 62111
Then generally stay away from threads.
Some basic edutation: In most cases database performance is limited by IO, not CPU. IO can partialyl be mitigated by using a lot of memory as buffers, hence large database servers have TONS of memory.
You run a small leightweight databasde. It likely is not running on a database server level hardware or a SSD - so it has a IO problem. Perforamcne will be limited by IO.
Now multiple threads make sure that the IO side (hard disc) is inefficieent, especialyl because a winform app is not running normally on a high end IO subsystem.
Ergo: if you want a faster query then:
Do not use multi threading - try to solve it on SQL level but accept that this may not be possible. THere is a reason companies still actually use real database servers to handle large data amounts. And SQLite may not be a good option - no chance saying it is or not as you totally ignore that side in your information.
Upvotes: 6