这是我们对一个表有DDL脚本:撷取行消耗的处理器时间的100%
CREATE TABLE [stat_ping] (
[lid] INT NOT NULL ON CONFLICT IGNORE,
[ping] NUMERIC(6, 2) NOT NULL ON CONFLICT IGNORE,
[timeping] DATETIME NOT NULL ON CONFLICT IGNORE);
对表中的数据样本:
lid ping timeping
2036 1 2013-02-26 10:46:27.000
2002 1 2013-02-26 10:46:27.000
2006 1 2013-02-26 10:46:27.000
2015 1 2013-02-26 10:46:27.000
2009 1 2013-02-26 10:46:27.000
2000 1 2013-02-26 10:46:27.000
2016 1 2013-02-26 10:46:27.000
2031 1 2013-02-26 10:46:27.000
2016 1 2013-02-26 10:46:27.000
2018 1 2013-02-26 10:46:27.000
2012 1 2013-02-26 10:46:27.000
2008 1 2013-02-26 10:46:28.000
2019 1 2013-02-26 10:46:29.000
2001 0 2013-02-26 10:46:29.000
2005 1 2013-02-26 10:46:29.000
113 1 2013-02-26 10:46:30.000
我们计算的可用性百分比使用此类查询的数据:
lock (Logger._lockObj)
{
using (SQLiteConnection sql = new SQLiteConnection(ConfigurationManager.ConnectionStrings["SQLite"].ToString()))
{
sql.Open();
foreach (var item in kk)
{
item.ping.stconn = 0;
string sqlquery = "select (sum(s.ping)*100/count(s.timeping)) from stat_ping as s where s.timeping between datetime('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','-1 day') and datetime('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "') and s.lid=" + item.lid;
using (SQLiteCommand comm = new SQLiteCommand(sqlquery, sql))
{
item.ping.stconn = Convert.ToByte(comm.ExecuteScalar());
}
}
}
}
我们使用Devart SQLite数据提供程序进行连接。表stat_ping包含大约100000行。因此,对于5个项目,计算百分比需要大约6-7秒,并且需要100%的处理器。
我知道我们应该使用单独的存储过程来计算所有项目的百分比,只需调用一次存储过程/函数,但任何人都可以分享关于实际性能和使用机会体验吗?
另一个我的项目将使用SQLite数据库作为SOAP消息日志的容器。我认为数据库可能需要很多空间,因为只有一对请求和响应需要150KB。
谢谢,伙计们!
是的,我有一个在盖子上的索引柱。它需要更快的时间(与索引),但仍然报价缓慢和100%的处理器。您能否介绍一下如何对旧数据进行归档?你有几排桌子? – kseen 2013-03-27 04:14:04