我正在使用 JDBC 将 1m 行插入到具有时间刻度的测试表中,性能似乎是普通 postgresql 的一半左右。通过采用 timescale-tune 实用程序建议的所有值来完成时间刻度调整。我究竟做错了什么?
private static void writeTable(String sql, int count, int commitCount,
Connection conn) throws Exception
{
conn.setAutoCommit(false);
long start = System.currentTimeMillis();
long t = start;
PreparedStatement stmt = conn.prepareStatement(sql);
for(int i = 0; i < count; i++)
{
stmt.setTimestamp(1, new Timestamp(t));
stmt.setDouble(2, 10.9);
stmt.addBatch();
t ++;
if(commitCount != -1 && ((i + 1) % commitCount) == 0)
{
stmt.executeBatch();
conn.commit();
}
}
stmt.executeBatch();
stmt.close();
conn.commit();
conn.close();
long diff = System.currentTimeMillis() - start;
System.out.println("Count : " + count);
System.out.println("Total Time : " + diff);
System.out.println("Writes/Sec : " + ((count * 1000) / diff));
}
Query: INSERT INTO kt_device_info (di_device_id, di_time, di_value) VALUES (1,?,?)
Table:
CREATE TABLE kt_device (
id BIGINT PRIMARY KEY,
d_name TEXT
);
insert into kt_device(id, d_name) values (1, 'dev-1');
CREATE TABLE kt_device_info (
di_device_id BIGINT REFERENCES kt_device NOT NULL,
di_time TIMESTAMPTZ NOT NULL,
di_value DOUBLE PRECISION NULL
);
SELECT create_hypertable('kt_device_info', 'di_time');
时间刻度:计数:1000000 总时间: 42026写入/秒:23794
Postgres 10: 计数:1000000 总时间:22573 写入/秒:44300
x86_64-pc-linux-gnu 上的 PostgreSQL 10.10 (Ubuntu 10.10-1.pgdg16.04+1),由 gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609,64 位编译
时标数据库 | 1.4.2 | 公共 | 为时间序列数据启用可扩展的插入和复杂查询
硬件:Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz,16GB 内存
Chunks:
SELECT show_chunks('kt_device_info');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_7_7_chunk
(1 row)