Skip to content

Commit

Permalink
fix: major performance issues with bytea performance #2240
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Jul 3, 2020
1 parent 410a6ab commit 69af267
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/pg/bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const pg = require('./lib')
const pool = new pg.Pool()

const params = {
text:
Expand All @@ -17,7 +16,7 @@ const seq = {
}

const exec = async (client, q) => {
const result = await client.query({
await client.query({
text: q.text,
values: q.values,
rowMode: 'array',
Expand All @@ -39,7 +38,9 @@ const bench = async (client, q, time) => {
const run = async () => {
const client = new pg.Client()
await client.connect()
console.log('start')
await client.query('CREATE TEMP TABLE foobar(name TEXT, age NUMERIC)')
await client.query('CREATE TEMP TABLE buf(name TEXT, data BYTEA)')
await bench(client, params, 1000)
console.log('warmup done')
const seconds = 5
Expand All @@ -61,7 +62,21 @@ const run = async () => {
console.log('insert queries:', queries)
console.log('qps', queries / seconds)
console.log('on my laptop best so far seen 5799 qps')
console.log()

console.log('')
console.log('Warming up bytea test')
await client.query({
text: 'INSERT INTO buf(name, data) VALUES ($1, $2)',
values: ['test', Buffer.allocUnsafe(104857600)],
})
console.log('bytea warmup done')
const start = Date.now()
const results = await client.query('SELECT * FROM buf')
const time = Date.now() - start
console.log('bytea time:', time, 'ms')
console.log('bytea length:', results.rows[0].data.byteLength, 'bytes')
console.log('on my laptop best so far seen 1107ms and 104857600 bytes')

await client.end()
await client.end()
}
Expand Down

0 comments on commit 69af267

Please sign in to comment.