-
Notifications
You must be signed in to change notification settings - Fork 4
/
stress_test.js
38 lines (35 loc) · 909 Bytes
/
stress_test.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
const fetch = require('node-fetch');
const Balancer = require('./lib/balancer');
const balancer = new Balancer({
poolExpired: 1 * 60 * 1000,
maxConcurrent: 15,
minTime: 100,
timeout: 3 * 1000,
proxyTimeout: 2 * 1000,
fetchProxies() {
return fetch('https://www.cool-proxy.net/proxies.json')
.then(res => res.json())
.then(proxies => {
return proxies
.filter(proxy => proxy.working_average > 70)
.map(proxy => `http://${proxy.ip}:${proxy.port}`)
})
}
});
let promises = [];
for (let i = 0; i < 100; i++) {
promises.push(balancer.request('https://ipv4.icanhazip.com')
.then(res => res.text())
.then(body => {
body = body.trim();
console.log(`completed: ${i}, ip: ${body}`);
return body;
})
.catch(err => {
console.error(err)
})
);
}
Promise.all(promises).then(result => {
console.log(result);
})