-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg-node-pg.js
More file actions
41 lines (32 loc) · 945 Bytes
/
Copy pathpg-node-pg.js
File metadata and controls
41 lines (32 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Pool } from "pg";
import { Stats } from './lib/bench.js'
const pool_size = 3
const sql = new Pool({
host: 'tfb-database',
user: 'benchmarkdbuser',
password: 'benchmarkdbpass',
database: 'hello_world',
port: 5432,
max: pool_size, // Maximum connections in pool
idle_timeout: 30, // Close idle connections after 30s
max_lifetime: 0, // Connection lifetime in seconds (0 = forever)
connect_timeout: 30, // Timeout when establishing new connections
ssl: false,
});
const stats = new Stats()
const query = { text: `SELECT id FROM Fortune`, name: 'foo' }
async function connection () {
let values = await sql.query(query)
stats.rps++
stats.conn++
while (values.rows.length === 12) {
values = await sql.query(query)
stats.rps++
}
}
const connections = []
for (let i = 0; i < pool_size; i++) {
connections.push(connection())
}
setInterval(() => stats.log(), 1000)
await Promise.all(connections)