参考资料 SQLite使用了某种锁定机制,可以防止您在数据库上执行并发操作。下面的连接介绍了sqlite锁的机制 https://blog.csdn.net/scyatcs/article/details/82690544
看下来,我感觉还是得上层自己加锁。 sqlite 并发处理
https://blog.csdn.net/cuit/article/details/21975807
https://blog.csdn.net/qingzhuyuxian/article/details/79767917?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164725837016780366572012%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=164725837016780366572012&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-79767917.142v2pc_search_quality_down,143v4control&utm_term=SQLite%E5%B9%B6%E5%8F%91&spm=1018.2226.3001.4187
性能测试
insert 插入
1.插入1000条数据,耗时6S
TJ_GSCJ_DEVINFO.ID = 3;
TJ_GSCJ_DEVINFO.DEV_NAME = "TJ_GSCJ";
TJ_GSCJ_DEVINFO.DEV_CMD_TABLE_NAME = "TJ_GSCJ_CMDTABLE";
TJ_GSCJ_DEVINFO.COMUNITATE_MODE = "TCP_SERVER";
TJ_GSCJ_DEVINFO.TCP_IP = "127.0.0.1";
TJ_GSCJ_DEVINFO.TCP_PORT = "5000";
TJ_GSCJ_DEVINFO.UDP_IP_SRC = "Jameqs";
TJ_GSCJ_DEVINFO.UDP_PORT_SRC = "Jameqs";
TJ_GSCJ_DEVINFO.UDP_PORT_DST = "Jameqs";
TJ_GSCJ_DEVINFO.UDP_IP_DST = "Jameqs";
TJ_GSCJ_DEVINFO.UDPMC_IP = "Jameqs";
TJ_GSCJ_DEVINFO.UDPMC_IP_RX = "Jameqs";
TJ_GSCJ_DEVINFO.UDPMC_IP_TX = "Jameqs";
TJ_GSCJ_DEVINFO.UDPMC_PORT_RX = "Jameqs";
TJ_GSCJ_DEVINFO.UDPMC_PORT_TX = "Jameqs";
printf_init_log("start sqlite_orm_write_test");
int key = 1000; //写1000条大概,耗时6
while (key != 0)
{
storage.insert(TJ_GSCJ_DEVINFO); //大概在4-8ms
key--;
}
printf_init_log("#############################start read sqlite_orm_write_test");
2.单条数据插入时间
storage.replace(SQLORM_XPRO_DEVINFO{1, "James", "James", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston", "Houston"}); //大概在6-8ms
storage.insert(TJ_GSCJ_DEVINFO); //大概在4-8ms
读取
1.读取耗时
同一时间只有一个线程在做读取
// 读取次数 耗时
// 90000 57-58ms
// 一次读6000 4-5ms
// 1000 2m
// 500 1m
printf_init_log("#############################start read sqlite_orm_write_test");
auto simpleRows = storage.select(columns(&SQLORM_XPRO_DEVINFO::ID, &SQLORM_XPRO_DEVINFO::DEV_NAME, &SQLORM_XPRO_DEVINFO::DEV_CMD_TABLE_NAME)); //几乎不耗时 小于1ms
printf_init_log("#############################end read sqlite_orm_write_test");
2.一对一的读取
循环读取,不带延时。读取正常,没有闪退
void *thread_GSCJQ1(void *arg)
{
while (1)
{
LOG(INFO) << "#############################start read sqlite_orm_write_test";
try
{
auto simpleRows = storage1.select(columns(&SQLORM_XPRO_DEVINFO::ID, &SQLORM_XPRO_DEVINFO::DEV_NAME, &SQLORM_XPRO_DEVINFO::DEV_CMD_TABLE_NAME)); //几乎不耗时 小于1ms
}
catch (const std::system_error &e)
{
cout << "11111111111" << e.what() << endl;
}
}
}
3.多对一的读取
起两个线程,循环读取,不带延时。读取正常,没有闪退
注意,两个线程的句柄需要不同。
void *thread_GSCJQ1(void *arg)
{
while (1)
{
LOG(INFO) << "#############################start read sqlite_orm_write_test";
try
{
auto simpleRows = storage1.select(columns(&SQLORM_XPRO_DEVINFO::ID, &SQLORM_XPRO_DEVINFO::DEV_NAME, &SQLORM_XPRO_DEVINFO::DEV_CMD_TABLE_NAME)); //几乎不耗时 小于1ms
}
catch (const std::system_error &e)
{
cout << "11111111111" << e.what() << endl;
}
}
}
void *thread_GSCJQ2(void *arg)
{
while (1)
{
LOG(TRACE) << "__________________start read sqlite_orm_write_test";
try
{
auto simpleRows = storage2.select(columns(&SQLORM_XPRO_DEVINFO::ID, &SQLORM_XPRO_DEVINFO::DEV_NAME, &SQLORM_XPRO_DEVINFO::DEV_CMD_TABLE_NAME)); //几乎不耗时 小于1ms
}
catch (const std::system_error &e)
{
cout << "22222222" << e.what() << endl;
}
}
}
|