I write my code to select concurrent in 3 threads with one-thread-one-handle; I found that it is slower than in 1 thread;
Here are my test data:
It's a table(index uint32) with 100000 items;
when I select 100000 items(all items) in 3 threads:
0: 1443185531.782627, info: <NSThread: 0x13f99ac40>{number = 4, name = (null)} read ready
1: 1443185531.782634, cost 0.000007, info: <NSThread: 0x13f99ac40>{number = 4, name = (null)} read start
2: 1443185533.365550, cost 1.582916, info: <NSThread: 0x13f99ac40>{number = 4, name = (null)} read end
0: 1443185531.772624, info: <NSThread: 0x13f871e60>{number = 2, name = (null)} read ready
1: 1443185531.782659, cost 0.010035, info: <NSThread: 0x13f871e60>{number = 2, name = (null)} read start
2: 1443185533.372972, cost 1.590313, info: <NSThread: 0x13f871e60>{number = 2, name = (null)} read end
0: 1443185531.773191, info: <NSThread: 0x13f99a6a0>{number = 3, name = (null)} read ready
1: 1443185531.782636, cost 0.009445, info: <NSThread: 0x13f99a6a0>{number = 3, name = (null)} read start
2: 1443185533.393716, cost 1.611080, info: <NSThread: 0x13f99a6a0>{number = 3, name = (null)} read end
You can see it costs 1.5s average.
But when I change to select 100000 items(all items) in 1 thread:
0: 1443185738.427020, info: <NSThread: 0x14d970990>{number = 2, name = (null)} read ready
1: 1443185738.427106, cost 0.000086, info: <NSThread: 0x14d970990>{number = 2, name = (null)} read start
2: 1443185739.020410, cost 0.593304, info: <NSThread: 0x14d970990>{number = 2, name = (null)} read end
The cost comes to 0.5s.
So I confuse that will multithread reading slow down the performance of sqlite3.
As I know, reading use the shared-mutex, which can be shared in multithread. Lower performance should not be happened.
Is anyone can solve my confusing?
Additional: sqlite3 is in WAL, SQLITE_CONFIG_MULTITHREAD mode, without any manually mutex.
Aucun commentaire:
Enregistrer un commentaire