SQLite数据库优化方案

有两个线程,一个是不停地从网络接收数据存入数据库中,另一个线程是根据不同的条件从数据库库中查询数据;
根据不同的日期创建的不同的一组数据库表;
插入或查询的数据量都比较大;
在插入数据库时查询数据会很慢甚至程序会崩溃。
请问有什么好的优化方案?

sqlite是一种小型轻量化的数据库,用于单机,不要求什么并发,数据量不大的客户端环境。如果你要大量的数据的插入、查询,应该用sql server、mysql、oracle、db2之类的服务器数据库。

做一个不是严格意义上的用程序写死的负载均衡。做两个数据库。甚至三个。

sqlite对于写会有锁,所以会导致性能不行

 SQLite supports an unlimited number of simultaneous readers, but it will only allow one writer at any instant in time. For many situations, this is not a problem. Writer queue up. Each application does its database work quickly and moves on, and no lock lasts for more than a few dozen milliseconds. But there are some applications that require more concurrency, and those applications may need to seek a different solution.

database对象枷锁把

SQLite作为一个嵌入式数据库,锁的粒度较粗(没有行锁),所以不适合高并发的场景下。这不是优化可以解决的,可以选用postgresql等合适的数据库

可以设计二个数据库,一个用来读数据的,另一个是用来写数据的。