-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node: improve GetActiveHandles performance
Improve performance of process._getActiveHandles by sending handles in batches to JS to be set on the passed Array. Add test to check proper active handles are returned. Alter implementation of GetActiveRequests to match GetActiveHandles' implementation. PR-URL: #3780 Reviewed-By: Fedor Indutny <fedor@indutny.com>
- Loading branch information
1 parent
e742422
commit c8fc217
Showing
2 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const NUM = 8; | ||
const connections = []; | ||
const clients = []; | ||
var clients_counter = 0; | ||
|
||
const server = net.createServer(function listener(c) { | ||
connections.push(c); | ||
}).listen(common.PORT, function makeConnections() { | ||
for (var i = 0; i < NUM; i++) { | ||
net.connect(common.PORT, function connected() { | ||
clientConnected(this); | ||
}); | ||
} | ||
}); | ||
|
||
|
||
function clientConnected(client) { | ||
clients.push(client); | ||
if (++clients_counter >= NUM) | ||
checkAll(); | ||
} | ||
|
||
|
||
function checkAll() { | ||
const handles = process._getActiveHandles(); | ||
|
||
clients.forEach(function(item) { | ||
assert.ok(handles.indexOf(item) > -1); | ||
item.destroy(); | ||
}); | ||
|
||
connections.forEach(function(item) { | ||
assert.ok(handles.indexOf(item) > -1); | ||
item.end(); | ||
}); | ||
|
||
assert.ok(handles.indexOf(server) > -1); | ||
server.close(); | ||
} |