SQLite Forum

High cpu usage of System.Data.SQLite.SQLiteConnection..ctor
Login
Hi, I am using System.Data.SQLite, version 1.0.113.7, dotnet framework project. My code creates the SQLiteConnection instance for each query and dispose it after the usage. But I found high cpu usage in the SQLiteConnection creation. As first I suspect it is my connection pool setting issues so I extend the connection pool size to 256 but found not help. I dump the CPU usage as below. The package name is mocked as 'MyPackage'.


|Function Name|Total CPU \[unit, %\]|Self CPU \[unit, %\]|Module|Category|
|-|-|-|-|-|
|\|\|\|\|\|\|\|\|\|\|\|\| + MyPackage.Local.SQLiteDataAccess.SQLiteAdapter.ExecuteScalarActionQuery\(string, System.Action\<System.Data.IDataReader\>, System.Collections.Generic.Dictionary\<string, string\>\)|617 \(4.47 %\)|1 \(0.01 %\)|MyPackageInternalProvider.dll|IO \| File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| + System.Data.SQLite.SQLiteConnection..ctor\(string, bool\)|251 \(1.82 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\|\| + System.Data.SQLite.UnsafeNativeMethods.Initialize\(\)|231 \(1.67 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.UnsafeNativeMethods.GetSettingValue\(string, string\)|133 \(0.96 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.UnsafeNativeMethods.SearchForDirectory\(ref string, ref string, ref bool\)|92 \(0.67 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.UnsafeNativeMethods.PreLoadSQLiteDll\(string, string, bool, ref string, ref int\)|6 \(0.04 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.SQLiteLog.Initialize\(string\)|20 \(0.14 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| - MyPackage.Local.SqlDbLogger\<T\>.SelectRecord.AnonymousMethod\_\_0\(System.Data.IDataReader\)|240 \(1.74 %\)|10 \(0.07 %\)|MyPackageInternalProvider.dll|IO \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.SQLiteDataReader.Read\(\)|45 \(0.33 %\)|2 \(0.01 %\)|System.Data.SQLite.dll|File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.SQLiteCommand.ExecuteReader\(System.Data.CommandBehavior\)|42 \(0.30 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|File System \| Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| - System.Data.SQLite.SQLiteConnection.Open\(\)|28 \(0.20 %\)|0 \(0.00 %\)|System.Data.SQLite.dll|Kernel|
|\|\|\|\|\|\|\|\|\|\|\|\|\| - MyPackage.Local.SQLiteDataAccess.SQLiteAdapter.ExecuteScalarActionQuery\(string, System.Action\<System.Data.IDataReader\>, System.Collections.Generic.Dictionary\<string, string\>\)|7 \(0.05 %\)|0 \(0.00 %\)|MyPackageInternalProvider.dll|Kernel|


The System.Data.SQLite.SQLiteConnection..ctor takes 1.82% cpu usage, compared with the 4.47% cpu usage of the total query execution. This one of the method cpu dump. In fact, the total cpu usage of the System.Data.SQLite.SQLiteConnection..ctor is over 20% in whole process. I don't think this is normal and I wonder why System.Data.SQLite.UnsafeNativeMethods.Initialize() take some many cpu? I also doubt that it is my error usage of connection. Can someone help me?