-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg-just.js
More file actions
69 lines (57 loc) · 1.38 KB
/
Copy pathpg-just.js
File metadata and controls
69 lines (57 loc) · 1.38 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const postgres = require('@pg')
const socket = require('@socket')
const dns = require('@dns')
const { createSocket } = socket
const { getIPAddress } = dns
const { constants } = postgres
const { BinaryInt, VarChar } = constants
const db = {
hostname: 'tfb-database',
user: 'benchmarkdbuser',
pass: 'benchmarkdbpass',
database: 'hello_world',
version: constants.PG_VERSION,
port: 5432
}
async function create_socket () {
const sock = createSocket()
const ip = await getIPAddress(db.hostname)
await sock.connect(ip, db.port)
const pg = await postgres.createSocket(sock, db)
sock.noDelay = false
const fortunes = {
portal: '',
formats: [],
name: 'fortunes',
maxRows: 0,
params: [],
sql: 'select id from Fortune',
fields: [
{ format: BinaryInt, name: 'id' }
]
}
const getFortunes = await pg.compile(fortunes)
const fn = getFortunes
async function client () {
let i = 0
while (i < 1000000) {
await fn()
rps++
}
}
return { client }
}
let rps = 0
just.setInterval(() => {
const { user, system } = just.cpuUsage()
const { rss } = just.memoryUsage()
just.print(`rps ${rps} rss ${rss} usr ${user} sys ${system} tot ${user + system}`)
rps = 0
}, 1000)
const clients = []
for (let i = 0; i < 3; i++) {
const s = await create_socket()
clients.push(s.client())
}
await Promise.all(clients)
sock.close()