-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathtest-max-pool-size.js
96 lines (86 loc) · 3.87 KB
/
test-max-pool-size.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var common = require("./common")
, ibmdb = require("../")
, pool = new ibmdb.Pool()
, connectionString = common.connectionString
, assert = require("assert")
, connectCount = 12;
pool.setMaxPoolSize(5); // Max no of active connections.
//pool.setConnectTimeout(8); // No timeout. connection request will remain in queue.
var elapsedTime = ibmdb.getElapsedTime;
var ret = pool.init(3, connectionString);
if(typeof ret === 'object') assert.equal(ret.message, undefined);
//moment().format("YYYY-MM-DD HH:mm:ss.SSS"));
console.log(elapsedTime(), "Started pool.open, populate a table MTAB1 of 130 rows.");
pool.open(connectionString, function( err, conn) {
try { conn.querySync("drop table mtab1");
conn.querySync("drop table mtab2"); } catch(e) {};
conn.querySync("create table mtab1(c1 varchar(30), c2 varchar(20))");
conn.querySync("create table mtab2(c1 varchar(30), c2 varchar(20))");
if (common.isZOS) {
// Db2 on z/OS does not support multi-row inserts
conn.querySync("Insert into mtab1 values ('1', 'bimal')");
conn.querySync("Insert into mtab1 values ('2', 'kumar')");
conn.querySync("Insert into mtab1 values ('3', 'jha')");
conn.querySync("Insert into mtab1 values ('4', 'kamal')");
conn.querySync("Insert into mtab1 values ('5', 'ibm')");
conn.querySync("Insert into mtab1 values ('1', 'bimal')");
conn.querySync("Insert into mtab1 values ('2', 'kumar')");
conn.querySync("Insert into mtab1 values ('3', 'jha')");
conn.querySync("Insert into mtab1 values ('4', 'kamal')");
conn.querySync("Insert into mtab1 values ('5', 'ibm')");
} else {
conn.querySync("Insert into mtab1 values ('1', 'bimal'),('2','kumar'),('3', 'jha'), ('4', 'kamal'), ('5', 'ibm')");
conn.querySync("Insert into mtab1 values ('1', 'bimal'),('2','kumar'),('3', 'jha'), ('4', 'kamal'), ('5', 'ibm')");
}
for(var i = 0; i < 3 ; i++) { // 4 is 340 rows and 6 is 2330 rows
conn.querySync("insert into mtab2 (select * from mtab1)");
conn.querySync("insert into mtab1 (select * from mtab2)");
}
conn.querySync("drop table mtab2");
console.log(elapsedTime(), "Inserted rows in mtab1 = ", conn.querySync("select count(*) from mtab1")[0]['1']);
conn.close(function(err){});
});
ibmdb.debug(true);
openConnectionsUsingPool();
function openConnectionsUsingPool() {
for (var x = 1; x <= connectCount; x++) {
(function (connectionIndex) {
console.log("Opening connection #", connectionIndex);
pool.open(connectionString, function (err, connection) {
if (err) {
console.error("error for connection %d: %s",
connectionIndex, err.message);
if (connectionIndex == connectCount) {
console.log("Going to close connections.. \n");
closeConnections();
}
return false;
}
console.log(elapsedTime(), "Connection " + connectionIndex + " opened. Start execution of Query" + connectionIndex + "\n");
var startTime = new Date();
connection.query("select c1, c2 from mtab1", function(err, data) {
if(err) console.log(err);
var totalTime = (new Date() - startTime)/1000;
//var qtime = parseInt(totalTime%60);
console.log(elapsedTime(), "Total execution time for Query"+connectionIndex+" = ", totalTime, "sec.");
if (connectionIndex == connectCount) {
connection.querySync("drop table mtab1");
console.log("Going to close connections.. \n");
closeConnections();
}
else
{
connection.close(function() {
console.log(elapsedTime(), "Connection " + connectionIndex + " closed.");
});
}
});
});
})(x);
}
}
function closeConnections () {
pool.close(function () {
console.error("pool closed");
});
}