Skip to content

Commit 69af267

Browse files
committed
fix: major performance issues with bytea performance #2240
1 parent 410a6ab commit 69af267

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/pg/bench.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const pg = require('./lib')
2-
const pool = new pg.Pool()
32

43
const params = {
54
text:
@@ -17,7 +16,7 @@ const seq = {
1716
}
1817

1918
const exec = async (client, q) => {
20-
const result = await client.query({
19+
await client.query({
2120
text: q.text,
2221
values: q.values,
2322
rowMode: 'array',
@@ -39,7 +38,9 @@ const bench = async (client, q, time) => {
3938
const run = async () => {
4039
const client = new pg.Client()
4140
await client.connect()
41+
console.log('start')
4242
await client.query('CREATE TEMP TABLE foobar(name TEXT, age NUMERIC)')
43+
await client.query('CREATE TEMP TABLE buf(name TEXT, data BYTEA)')
4344
await bench(client, params, 1000)
4445
console.log('warmup done')
4546
const seconds = 5
@@ -61,7 +62,21 @@ const run = async () => {
6162
console.log('insert queries:', queries)
6263
console.log('qps', queries / seconds)
6364
console.log('on my laptop best so far seen 5799 qps')
64-
console.log()
65+
66+
console.log('')
67+
console.log('Warming up bytea test')
68+
await client.query({
69+
text: 'INSERT INTO buf(name, data) VALUES ($1, $2)',
70+
values: ['test', Buffer.allocUnsafe(104857600)],
71+
})
72+
console.log('bytea warmup done')
73+
const start = Date.now()
74+
const results = await client.query('SELECT * FROM buf')
75+
const time = Date.now() - start
76+
console.log('bytea time:', time, 'ms')
77+
console.log('bytea length:', results.rows[0].data.byteLength, 'bytes')
78+
console.log('on my laptop best so far seen 1107ms and 104857600 bytes')
79+
6580
await client.end()
6681
await client.end()
6782
}

0 commit comments

Comments
 (0)