Java 对于插入,TimescaleDB比普通postgresql 10慢
我使用JDBC将1m行插入带有时间刻度的测试表中,其性能似乎是普通postgresql的一半左右。时间刻度调整是通过获取时间刻度调整实用程序建议的所有值来完成的。我做错了什么Java 对于插入,TimescaleDB比普通postgresql 10慢,java,postgresql,jdbc,timescaledb,Java,Postgresql,Jdbc,Timescaledb,我使用JDBC将1m行插入带有时间刻度的测试表中,其性能似乎是普通postgresql的一半左右。时间刻度调整是通过获取时间刻度调整实用程序建议的所有值来完成的。我做错了什么 private static void writeTable(String sql, int count, int commitCount, Connection conn) throws Exception { conn.setAutoCommit(false); long
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));
}
时间刻度:
计数:1000000
总时间:42026
写入/秒:23794
Postgres 10:
计数:1000000
总时间:22573
写入/秒:44300
PostgreSQL 10.10(Ubuntu 10.10-1.pgdg16.04+1)在x86_64-pc-linux-gnu上,由gcc(Ubuntu 5.4.0-6ubuntu1~16.04.11)5.4.0 20160609编译,64位
timescaledb | 1.4.2 | public |支持可伸缩插入和复杂查询时间序列数据
硬件:
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)
查看代码,您正在创建相隔毫秒的时间戳。这就解释了为什么你只有一块。默认区块大小为7天。在这种情况下,您可能希望将分区设置得更小一些,比如几秒钟。您可以通过以下方式更改区块大小:选择设置区块时间间隔(“kt\U设备信息”,4000) 查看您的代码,您正在创建相隔毫秒的时间戳。这就解释了为什么你只有一块。默认区块大小为7天。在这种情况下,您可能希望将分区设置得更小一些,比如几秒钟。您可以通过以下方式更改区块大小:选择设置区块时间间隔(“kt\U设备信息”,4000) 使用
perf
查看在哪个可执行函数中花费的时间。您需要安装调试符号。在TimescaleDB中,具有适当大小的块非常重要。你能检查并添加到问题中有多少块被创建了吗?创建多个块会对性能产生负面影响。请使用perf
查看时间花在哪个可执行文件的哪个函数上。您需要安装调试符号。在TimescaleDB中,具有适当大小的块非常重要。你能检查并添加到问题中有多少块被创建了吗?创建许多块将对性能产生负面影响。
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');
Chunks:
SELECT show_chunks('kt_device_info');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_7_7_chunk
(1 row)