forked from tediousjs/tedious-connection-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add memory test and load test
- Loading branch information
Showing
5 changed files
with
136 additions
and
17 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
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,57 @@ | ||
var ConnectionPool = require('../lib/connection-pool'); | ||
var Request = require('tedious').Request; | ||
|
||
var poolConfig = {min: 20, max: 100, log: true}; | ||
var pool = new ConnectionPool(poolConfig, { | ||
userName: 'test', | ||
password: 'test', | ||
server: 'dev1' | ||
}); | ||
|
||
var clients = 1000; | ||
var connections = 1000; | ||
var total = clients * connections; | ||
|
||
var c = 0; | ||
var p = 0; | ||
|
||
var createRequest = function (connection) { | ||
if (c >= total) | ||
return; | ||
|
||
var request = new Request('select 42', function () { | ||
connection.release(); | ||
|
||
c++; | ||
var m = Math.round(c / total * 100); | ||
if (m > p) { | ||
p = m; | ||
console.log(p); | ||
} | ||
|
||
//console.log(c); | ||
if (c === total - 1) { | ||
console.log('done'); | ||
pool.drain(); | ||
|
||
setTimeout(function() { | ||
process.exit(); | ||
}, 10000); | ||
return; | ||
} | ||
|
||
setTimeout(function() { | ||
pool.acquire(createRequest); | ||
}, 0); | ||
}); | ||
|
||
request.on('row', function (columns) { | ||
//console.log(columns[0].value); | ||
}); | ||
|
||
connection.execSql(request); | ||
}; | ||
|
||
for (var i = 0; i < clients; i++) { | ||
pool.acquire(createRequest); | ||
} |
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,28 @@ | ||
//test for memory leak on bad connections | ||
var ConnectionPool = require('../lib/connection-pool'); | ||
var fs = require('fs'); | ||
|
||
var count = 0; | ||
var mem = []; | ||
var groupCount = 10; | ||
var poolSize = 1000; | ||
|
||
var pool = new ConnectionPool({ max: poolSize, min: poolSize, retryDelay: 1}, { | ||
userName: 'testLogin', | ||
password: 'wrongPassword', | ||
server: 'localhost' | ||
}); | ||
|
||
pool.on('error', function() { | ||
var i = Math.floor(count++ / poolSize); | ||
if (i === groupCount) { | ||
var previous = 0; | ||
for (var f = 0; f < groupCount; f++) { | ||
var size = (mem[f] / poolSize); | ||
fs.writeSync(1, ((f+1) * poolSize) + ': ' + Math.round(mem[f] / poolSize * 100) + 'KB\n'); | ||
previous = size; | ||
} | ||
process.exit(0); | ||
} | ||
mem[i] = (mem[i] || 0) + (process.memoryUsage().heapUsed / 1000); //kilobytes | ||
}); |