This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
load.js
99 lines (85 loc) · 2.37 KB
/
load.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict'
const autocannon = require('autocannon')
const FormData = require('form-data')
const fs = require('fs')
const ipfsdCtl = require('ipfsd-ctl')
const logger = require('./src/logger')
const imageHash = 'QmcJwbSPxVgpLsnN3ESAeZ7FRSapYKa27pWFhY9orsZat7'
const ipfsFactory = ipfsdCtl.create({
type: 'js'
})
require('./src/app')
async function spawnIpfs() {
return new Promise((resolve, reject) => {
ipfsFactory.spawn(
{
disposable: true,
defaultAddrs: true
},
(err, node) => {
if (err) {
reject(err)
}
node.api.util.addFromFs('./fixtures/sample_1mb.jpg')
resolve(node)
}
)
})
}
async function loadTest(url, requests = []) {
const ipfsNode = await spawnIpfs()
let autocannonInstance
return new Promise((resolve, reject) => {
autocannonInstance = autocannon(
{
url: url,
connections: 10,
pipelining: 1,
duration: 30,
requests: requests
},
(err, res) => {
if (err) {
logger.error(err)
reject(err)
}
ipfsNode.stop()
resolve(res)
}
)
autocannon.track(autocannonInstance, {
renderLatencyTable: true
})
process.once('SIGINT', () => {
autocannonInstance.stop()
})
})
}
async function main() {
const fileBuffer = fs.readFileSync('./fixtures/sample_1mb.jpg')
const formData = new FormData()
formData.append('image', fileBuffer)
const downloadRequest = {
method: 'GET',
path: `/ipfs/${imageHash}`,
headers: {}
}
// const uploadRequest = {
// method: 'POST',
// path: '/api/v0/add',
// body: formData.toString(),
// headers: formData.getHeaders()
// }
logger.debug('Starting load test of IPFS node')
await loadTest(`http://localhost:9090/ipfs/${imageHash}`, [downloadRequest])
// See https://github.com/OriginProtocol/origin/issues/794
// await loadTest(`http://localhost:5002/api/v0/add`, [uploadRequest])
logger.debug('Load test of IPFS node complete')
logger.debug('Starting load test of origin-ipfs-proxy')
await loadTest(`http://localhost:9999/ipfs/${imageHash}`, [downloadRequest])
// See https://github.com/OriginProtocol/origin/issues/794
// await loadTest(`http://localhost:9999/api/v0/add`, [uploadRequest])
logger.debug('Load test of origin-ipfs-proxy complete')
process.exit()
}
main()