Reputation: 31
I am inserting 1m rows into a test table with timescale using JDBC and the performance seems to be about half that of plain postgresql. Timescale tuning was done by taking all values suggested by the timescale-tune utility. What am I doing wrong?
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');
Timescale : Count : 1000000 Total Time : 42026 Writes/Sec : 23794
Postgres 10: Count : 1000000 Total Time : 22573 Writes/Sec : 44300
PostgreSQL 10.10 (Ubuntu 10.10-1.pgdg16.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609, 64-bit
timescaledb | 1.4.2 | public | Enables scalable inserts and complex queries for time-series data
Hardware: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz, 16GB Memory
Chunks:
SELECT show_chunks('kt_device_info');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_7_7_chunk
(1 row)
Upvotes: 3
Views: 1746
Reputation: 11
Looking at your code, you are creating timestamps that are milliseconds apart. That would explain why you only have one chunk. The default chunk size is 7 days. In this case you probably want to set the partitions smaller to something like a few seconds. You can change the chunk size with: SELECT set_chunk_time_interval('kt_device_info', 4000);
Upvotes: 1