|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 | 21 |
|
22 | 22 | 'use strict';
|
23 |
| -const common = require('../common'); |
| 23 | +require('../common'); |
24 | 24 | const assert = require('assert');
|
25 | 25 | const net = require('net');
|
26 | 26 |
|
27 | 27 | // settings
|
28 | 28 | const bytes = 1024 * 40;
|
29 |
| -const concurrency = 100; |
30 |
| -const connections_per_client = 5; |
| 29 | +const concurrency = 50; |
| 30 | +const connections_per_client = 3; |
31 | 31 |
|
32 | 32 | // measured
|
33 | 33 | let total_connections = 0;
|
34 | 34 |
|
35 | 35 | const body = 'C'.repeat(bytes);
|
36 | 36 |
|
37 | 37 | const server = net.createServer(function(c) {
|
38 |
| - console.log('connected'); |
39 | 38 | total_connections++;
|
40 |
| - console.log('#'); |
| 39 | + console.log('connected', total_connections); |
41 | 40 | c.write(body);
|
42 | 41 | c.end();
|
43 | 42 | });
|
44 | 43 |
|
45 |
| -function runClient(callback) { |
46 |
| - const client = net.createConnection(common.PORT); |
| 44 | +function runClient(port, callback) { |
| 45 | + const client = net.createConnection(port); |
47 | 46 |
|
48 | 47 | client.connections = 0;
|
49 | 48 |
|
@@ -79,17 +78,17 @@ function runClient(callback) {
|
79 | 78 | assert.ok(!client.fd);
|
80 | 79 |
|
81 | 80 | if (this.connections < connections_per_client) {
|
82 |
| - this.connect(common.PORT); |
| 81 | + this.connect(port); |
83 | 82 | } else {
|
84 | 83 | callback();
|
85 | 84 | }
|
86 | 85 | });
|
87 | 86 | }
|
88 | 87 |
|
89 |
| -server.listen(common.PORT, function() { |
| 88 | +server.listen(0, function() { |
90 | 89 | let finished_clients = 0;
|
91 | 90 | for (let i = 0; i < concurrency; i++) {
|
92 |
| - runClient(function() { |
| 91 | + runClient(server.address().port, function() { |
93 | 92 | if (++finished_clients === concurrency) server.close();
|
94 | 93 | });
|
95 | 94 | }
|
|
0 commit comments