| 101 | } |
| 102 | |
| 103 | function client(dur) { |
| 104 | const clientHandle = new TCP(TCPConstants.SOCKET); |
| 105 | const connectReq = new TCPConnectWrap(); |
| 106 | const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); |
| 107 | |
| 108 | if (err) |
| 109 | fail(err, 'connect'); |
| 110 | |
| 111 | connectReq.oncomplete = function() { |
| 112 | let bytes = 0; |
| 113 | clientHandle.onread = function(buffer) { |
| 114 | // We're not expecting to ever get an EOF from the client. |
| 115 | // Just lots of data forever. |
| 116 | if (!buffer) |
| 117 | fail('read'); |
| 118 | |
| 119 | // Don't slice the buffer. The point of this is to isolate, not |
| 120 | // simulate real traffic. |
| 121 | bytes += buffer.byteLength; |
| 122 | }; |
| 123 | |
| 124 | clientHandle.readStart(); |
| 125 | |
| 126 | // The meat of the benchmark is right here: |
| 127 | bench.start(); |
| 128 | |
| 129 | setTimeout(() => { |
| 130 | // report in Gb/sec |
| 131 | bench.end((bytes * 8) / (1024 * 1024 * 1024)); |
| 132 | process.exit(0); |
| 133 | }, dur * 1000); |
| 134 | }; |
| 135 | } |
| 136 | } |