-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg-bun.js
More file actions
54 lines (46 loc) · 1.3 KB
/
Copy pathpg-bun.js
File metadata and controls
54 lines (46 loc) · 1.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Stats } from './lib/bench.js'
import { SQL } from "bun";
const pool_size = 3
/*
const config = {
// url: "postgres://benchmarkdbuser:benchmarkdbpass@localhost/hello_world",
// url: "postgres://user:pass@localhost:5432/dbname",
// path: './postgresql',
path: './postgresql/.s.PGSQL.5432',
// hostname: "tfb-database",
// port: 5432,
database: "hello_world",
user: "benchmarkdbuser",
password: "benchmarkdbpass",
max: pool_size, // Maximum connections in pool
idleTimeout: 30, // Close idle connections after 30s
maxLifetime: 0, // Connection lifetime in seconds (0 = forever)
connectionTimeout: 30, // Timeout when establishing new connections
tls: false,
}
*/
const config = {
max: pool_size,
path: './postgresql/.s.PGSQL.5432',
user: 'benchmarkdbuser',
password: 'benchmarkdbpass',
database: 'hello_world'
}
const sql = new SQL(config);
const stats = new Stats()
async function connection () {
const foo = await sql.reserve()
stats.conn++
let values = await foo`SELECT id FROM Fortune`.raw()
stats.rps++
while (values.length === 12) {
values = await foo`SELECT id FROM Fortune`.raw()
stats.rps++
}
}
const connections = []
for (let i = 0; i < pool_size; i++) {
connections.push(connection())
}
setInterval(() => stats.log(), 1000)
await Promise.all(connections)