我有一個windows IoT應用程序,它從一些數據源捕獲數據並將其存儲在持久存儲上。這裏是我的技術堆棧Windows IoT上的SQLite性能調整
- 的Windows 10物聯網核心
- UWP後臺應用程序(C#)
- SQLite的
- SQLite,讓通用Windows平臺3.19.3
- SQLite.NET-PCL的NuGet https://github.com/oysteinkrog/SQLite.Net-PCL
我正在使用Raspberry Pi 3來測試此解決方案。爲了存儲數據,我決定使用SQLite。以下是表格的架構
public class tblDataLog
{
[PrimaryKey]
[AutoIncrement]
public int RecordId { get; set; }
public int? Param1 { get; set; }
public int? Param2 { get; set; }
public double? Param2 { get; set; }
public double? Param4 { get; set; }
public double? Param5 { get; set; }
public int? Param6 { get; set; }
public int? Param7 { get; set; }
public double? Param7 { get; set; }
public double? Param8 { get; set; }
public double? Param9 { get; set; }
public double? Param10 { get; set; }
public double? Param11 { get; set; }
[Indexed]
public DateTime RecordedOn { get; set; }
}
對於測試,我在此表中存儲了200萬行,並且沒有執行插入操作。以下是我的代碼爲最後6小時
獲取數據var commandstr = $"select * from tblDataLog Where RecordedOn >= " + DateTime.Now.AddHours(-6) + " AND RecordedOn <= " + DateTime.Now;
var cmd = Connection.CreateCommand(commandstr);
var sensorDataQuery = cmd.ExecuteQuery<tblDataLog>(); //This line takes around 90 seconds on average to complete
的問題是,只有六個小時的數據(大約216000行,數據傳輸速率爲10Hz),它正在約90秒,以獲取記錄這是太慢了。最後,我需要將數據轉換爲CSV並提供文件下載,我試圖將文件存儲爲與SQLite方法相比指數級快速的平面csv文件,就像上述情況一樣,它只需要5秒鐘一般。
我想知道我有什麼選擇來優化SQLite的性能(如果有的話)?這是非常簡單的查詢,我懷疑它是由於SD卡存儲,我使用的是10級存儲卡,並且CSV也以合理的速度在同一張卡上工作。
任何建議在這方面高度讚賞。