Skip to content

Commit fb1d28a

Browse files
author
Christopher Jones
committed
Added PoolStatistics class
1 parent 7649129 commit fb1d28a

File tree

8 files changed

+1377
-610
lines changed

8 files changed

+1377
-610
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
**This release is under development and information may be incomplete**
66

7+
- Encapsulated the connection pool statistics in a [PoolStatistics
8+
Class](https://oracle.github.io/node-oracledb/doc/api.html#poolstatisticsclass).
9+
Added a
10+
[`poolstatistics.logStatistics()`](https://oracle.github.io/node-oracledb/doc/api.html#poolstatisticslogstatistics)
11+
function, equivalent to the existing `pool.logStatistics()` function. Exposed
12+
pool properties `user`, `connectString`, `edition`, `events`,
13+
`externalAuth`, and `homogeneous` on the Pool and PoolStatistics classes.
14+
715
## node-oracledb v5.2.0 (7 Jun 2021)
816

917
- Connection pool changes:

doc/api.md

Lines changed: 609 additions & 499 deletions
Large diffs are not rendered by default.

lib/oracledb.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const BaseDbObject = require('./dbObject.js');
4343
const Connection = require('./connection.js');
4444
const Lob = require('./lob.js');
4545
const Pool = require('./pool.js');
46+
const PoolStatistics = require('./poolStatistics.js');
4647
const ResultSet = require('./resultset.js');
4748
const SodaDatabase = require('./sodaDatabase.js');
4849
const SodaCollection = require('./sodaCollection.js');
@@ -380,6 +381,7 @@ proto.BaseDbObject = BaseDbObject;
380381
proto.Connection = Connection;
381382
proto.Lob = Lob;
382383
proto.Pool = Pool;
384+
proto.PoolStatistics = PoolStatistics;
383385
proto.ResultSet = ResultSet;
384386
proto.SodaDatabase = SodaDatabase;
385387
proto.SodaCollection = SodaCollection;

lib/pool.js

Lines changed: 33 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
const EventEmitter = require('events');
2323
const nodbUtil = require('./util.js');
2424
const util = require('util');
25+
const PoolStatistics = require('./poolStatistics.js');
26+
2527

2628
//-----------------------------------------------------------------------------
2729
// _checkRequestQueue()
@@ -328,44 +330,7 @@ function logStatistics() {
328330
if (stats === null) {
329331
throw new Error(nodbUtil.getErrorMessage('NJS-083'));
330332
}
331-
332-
console.log('\nPool statistics:');
333-
console.log('...gathered at:', new Date(stats.gatheredDate).toISOString());
334-
console.log('...up time (milliseconds):', stats.upTime);
335-
console.log('...up time from last reset (milliseconds)',
336-
stats.upTimeSinceReset);
337-
console.log('...connection requests:', stats.connectionRequests);
338-
console.log('...requests enqueued:', stats.requestsEnqueued);
339-
console.log('...requests dequeued:', stats.requestsDequeued);
340-
console.log('...requests failed:', stats.failedRequests);
341-
console.log('...requests exceeding queueMax:', stats.rejectedRequests);
342-
console.log('...requests exceeding queueTimeout:', stats.requestTimeouts);
343-
console.log('...current queue length:', stats.currentQueueLength);
344-
console.log('...maximum queue length:', stats.maximumQueueLength);
345-
console.log('...sum of time in queue (milliseconds):', stats.timeInQueue);
346-
console.log('...minimum time in queue (milliseconds):',
347-
stats.minimumTimeInQueue);
348-
console.log('...maximum time in queue (milliseconds):',
349-
stats.maximumTimeInQueue);
350-
console.log('...average time in queue (milliseconds):',
351-
stats.averageTimeInQueue);
352-
console.log('...pool connections in use:', stats.connectionsInUse);
353-
console.log('...pool connections open:', stats.connectionsOpen);
354-
console.log('Pool attributes:');
355-
console.log('...poolAlias:', stats.poolAlias);
356-
console.log('...queueMax:', stats.queueMax);
357-
console.log('...queueTimeout (milliseconds):', stats.queueTimeout);
358-
console.log('...poolMin:', stats.poolMin);
359-
console.log('...poolMax:', stats.poolMax);
360-
console.log('...poolIncrement:', stats.poolIncrement);
361-
console.log('...poolTimeout (seconds):', stats.poolTimeout);
362-
console.log('...poolPingInterval (seconds):', stats.poolPingInterval);
363-
console.log('...poolMaxPerShard:', stats.poolMaxPerShard);
364-
console.log('...sessionCallback:', stats.sessionCallback);
365-
console.log('...stmtCacheSize:', stats.stmtCacheSize);
366-
console.log('...sodaMetaDataCache:', stats.sodaMetaDataCache);
367-
console.log('Related environment variables:');
368-
console.log('...UV_THREADPOOL_SIZE:', stats.threadPoolSize);
333+
stats.logStatistics();
369334
}
370335

371336

@@ -375,54 +340,12 @@ function logStatistics() {
375340
// properties
376341
//-----------------------------------------------------------------------------
377342
function getStatistics() {
378-
let averageTimeInQueue;
379-
let stats = { };
380-
381-
// if the pool is not OPEN, throw appropriate err
382343
this._checkPoolOpen(false);
383344

384345
if (this._enableStatistics !== true) {
385346
return null;
386347
}
387-
388-
averageTimeInQueue = 0;
389-
390-
if (this._totalRequestsEnqueued !== 0) {
391-
averageTimeInQueue = Math.round(this._totalTimeInQueue /
392-
this._totalRequestsEnqueued);
393-
}
394-
395-
stats.gatheredDate = Date.now ();
396-
stats.upTime = stats.gatheredDate - this._createdDate;
397-
stats.upTimeSinceReset = stats.gatheredDate - this._timeOfReset;
398-
stats.connectionRequests = this._totalConnectionRequests;
399-
stats.requestsEnqueued = this._totalRequestsEnqueued;
400-
stats.requestsDequeued = this._totalRequestsDequeued;
401-
stats.failedRequests = this._totalFailedRequests;
402-
stats.rejectedRequests = this._totalRequestsRejected;
403-
stats.requestTimeouts = this._totalRequestTimeouts;
404-
stats.maximumQueueLength = this._maximumQueueLength;
405-
stats.currentQueueLength = this._connRequestQueue.length;
406-
stats.timeInQueue = this._totalTimeInQueue;
407-
stats.minimumTimeInQueue = this._minTimeInQueue;
408-
stats.maximumTimeInQueue = this._maxTimeInQueue;
409-
stats.averageTimeInQueue = averageTimeInQueue;
410-
stats.connectionsInUse = this.connectionsInUse;
411-
stats.connectionsOpen = this.connectionsOpen;
412-
stats.poolAlias = this.poolAlias;
413-
stats.queueMax = this.queueMax;
414-
stats.queueTimeout = this.queueTimeout;
415-
stats.poolMin = this.poolMin;
416-
stats.poolMax = this.poolMax;
417-
stats.poolIncrement = this.poolIncrement;
418-
stats.poolTimeout = this.poolTimeout;
419-
stats.poolPingInterval = this.poolPingInterval;
420-
stats.poolMaxPerShard = this.poolMaxPerShard;
421-
stats.stmtCacheSize = this.stmtCacheSize;
422-
stats.sodaMetaDataCache = this.sodaMetaDataCache;
423-
stats.threadPoolSize = process.env.UV_THREADPOOL_SIZE;
424-
425-
return stats;
348+
return new PoolStatistics(this);
426349
}
427350

428351

@@ -467,6 +390,35 @@ function _setup(poolAttrs, poolAlias, oracledb) {
467390
this._sessionCallback = poolAttrs.sessionCallback;
468391
}
469392

393+
// Properties - edition, events, externalAuth - values can be set globally
394+
// on oracledb and can be overridden at pool creation time.
395+
if (typeof poolAttrs.edition !== 'undefined') {
396+
this.edition = poolAttrs.edition;
397+
} else {
398+
this.edition = oracledb.edition;
399+
}
400+
401+
if (typeof poolAttrs.events !== 'undefined') {
402+
this.events = poolAttrs.events;
403+
} else {
404+
this.events = oracledb.events;
405+
}
406+
407+
if (typeof poolAttrs.externalAuth !== 'undefined') {
408+
this.externalAuth = poolAttrs.externalAuth;
409+
} else {
410+
this.externalAuth = oracledb.externalAuth;
411+
}
412+
413+
// Properties - homogeneous, user, connectString - are NOT global properties
414+
if (typeof poolAttrs.homogeneous !== 'undefined') {
415+
this.homogeneous = poolAttrs.homogeneous;
416+
} else {
417+
this.homogeneous = true;
418+
}
419+
this.user = poolAttrs.user || poolAttrs.userName;
420+
this.connectString = poolAttrs.connectString || poolAttrs.connectionString;
421+
470422
// register event handler for when request queue should be checked
471423
this.on('_checkRequestQueue', this._checkRequestQueue);
472424

lib/poolStatistics.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved
2+
//-----------------------------------------------------------------------------
3+
//
4+
// You may not use the identified files except in compliance with the Apache
5+
// License, Version 2.0 (the "License.")
6+
//
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0.
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
//
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
//-----------------------------------------------------------------------------
18+
19+
'use strict';
20+
21+
//-----------------------------------------------------------------------------
22+
// class PoolStatistics
23+
// collection of statistics metrics for Pool object
24+
//-----------------------------------------------------------------------------
25+
26+
class PoolStatistics {
27+
28+
constructor(pool) {
29+
let averageTimeInQueue = 0;
30+
31+
if (pool._totalRequestsEnqueued !== 0) {
32+
averageTimeInQueue = Math.round(pool._totalTimeInQueue /
33+
pool._totalRequestsEnqueued);
34+
}
35+
36+
this.gatheredDate = Date.now ();
37+
this.upTime = this.gatheredDate - pool._createdDate;
38+
this.upTimeSinceReset = this.gatheredDate - pool._timeOfReset;
39+
this.connectionRequests = pool._totalConnectionRequests;
40+
this.requestsEnqueued = pool._totalRequestsEnqueued;
41+
this.requestsDequeued = pool._totalRequestsDequeued;
42+
this.failedRequests = pool._totalFailedRequests;
43+
this.rejectedRequests = pool._totalRequestsRejected;
44+
this.requestTimeouts = pool._totalRequestTimeouts;
45+
this.maximumQueueLength = pool._maximumQueueLength;
46+
this.currentQueueLength = pool._connRequestQueue.length;
47+
this.timeInQueue = pool._totalTimeInQueue;
48+
this.minimumTimeInQueue = pool._minTimeInQueue;
49+
this.maximumTimeInQueue = pool._maxTimeInQueue;
50+
this.averageTimeInQueue = averageTimeInQueue;
51+
this.connectionsInUse = pool.connectionsInUse;
52+
this.connectionsOpen = pool.connectionsOpen;
53+
this.connectString = pool.connectString;
54+
this.edition = pool.edition;
55+
this.events = pool.events;
56+
this.externalAuth = pool.externalAuth;
57+
this.homogeneous = pool.homogeneous;
58+
this.poolAlias = pool.poolAlias;
59+
this.poolIncrement = pool.poolIncrement;
60+
this.poolMax = pool.poolMax;
61+
this.poolMaxPerShard = pool.poolMaxPerShard;
62+
this.poolMin = pool.poolMin;
63+
this.poolPingInterval = pool.poolPingInterval;
64+
this.poolTimeout = pool.poolTimeout;
65+
this.queueMax = pool.queueMax;
66+
this.queueTimeout = pool.queueTimeout;
67+
this.sodaMetaDataCache = pool.sodaMetaDataCache;
68+
this.stmtCacheSize = pool.stmtCacheSize;
69+
this.user = pool.user;
70+
this.threadPoolSize = process.env.UV_THREADPOOL_SIZE;
71+
}
72+
73+
//---------------------------------------------------------------------------
74+
// logStatistics()
75+
// To print the statistics metrics of the pool
76+
//---------------------------------------------------------------------------
77+
logStatistics() {
78+
console.log('\nPool statistics:');
79+
console.log('...gathered at:', new Date(this.gatheredDate).toISOString());
80+
console.log('...up time (milliseconds):', this.upTime);
81+
console.log('...up time from last reset (milliseconds)',
82+
this.upTimeSinceReset);
83+
console.log('...connection requests:', this.connectionRequests);
84+
console.log('...requests enqueued:', this.requestsEnqueued);
85+
console.log('...requests dequeued:', this.requestsDequeued);
86+
console.log('...requests failed:', this.failedRequests);
87+
console.log('...requests exceeding queueMax:', this.rejectedRequests);
88+
console.log('...requests exceeding queueTimeout:', this.requestTimeouts);
89+
console.log('...current queue length:', this.currentQueueLength);
90+
console.log('...maximum queue length:', this.maximumQueueLength);
91+
console.log('...sum of time in queue (milliseconds):', this.timeInQueue);
92+
console.log('...minimum time in queue (milliseconds):',
93+
this.minimumTimeInQueue);
94+
console.log('...maximum time in queue (milliseconds):',
95+
this.maximumTimeInQueue);
96+
console.log('...average time in queue (milliseconds):',
97+
this.averageTimeInQueue);
98+
console.log('...pool connections in use:', this.connectionsInUse);
99+
console.log('...pool connections open:', this.connectionsOpen);
100+
console.log('Pool attributes:');
101+
console.log('...connectString:', this.connectString);
102+
console.log('...edition:', this.edition);
103+
console.log('...events:', this.events);
104+
console.log('...externalAuth:', this.externalAuth);
105+
console.log('...homogeneous:', this.homogeneous);
106+
console.log('...poolAlias:', this.poolAlias);
107+
console.log('...poolIncrement:', this.poolIncrement);
108+
console.log('...poolMax:', this.poolMax);
109+
console.log('...poolMaxPerShard:', this.poolMaxPerShard);
110+
console.log('...poolMin:', this.poolMin);
111+
console.log('...poolPingInterval (seconds):', this.poolPingInterval);
112+
console.log('...poolTimeout (seconds):', this.poolTimeout);
113+
console.log('...queueMax:', this.queueMax);
114+
console.log('...queueTimeout (milliseconds):', this.queueTimeout);
115+
console.log('...sessionCallback:', this.sessionCallback);
116+
console.log('...sodaMetaDataCache:', this.sodaMetaDataCache);
117+
console.log('...stmtCacheSize:', this.stmtCacheSize);
118+
console.log('...user:', this.user);
119+
console.log('Related environment variables:');
120+
console.log('...UV_THREADPOOL_SIZE:', this.threadPoolSize);
121+
}
122+
}
123+
124+
module.exports = PoolStatistics;

test/list.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ Overview of node-oracledb functional tests
8484
2.14.1 allows username to be used as an alias for user
8585
2.14.2 both user and username specified
8686
2.14.3 uses username alias to login with SYSDBA privilege
87+
2.15 creation time non editable properties
88+
2.15.1 default edition value
89+
2.15.2 ORA$BASE edition value
90+
2.15.3 default value for events - undefined
91+
2.15.4 events - false
92+
2.15.5 events - true
93+
2.15.6 externalAuth - default undefined
94+
2.15.7 externalAuth - true
95+
2.15.8 externalAuth - false
96+
2.15.9 homogeneous - default true
97+
2.15.10 homogeneous - true
98+
2.15.11 homogeneous - false
99+
2.15.12 user name
100+
2.15.13 user name - undefined
101+
2.15.14 connectString
102+
103+
2.16 Pool non-configurable properties global/local override
104+
2.16.1 edition only globally set
105+
2.16.2 edition override
106+
2.16.3 edition override to empty string
107+
2.16.4 events override to true
108+
2.16.5 events override to false
109+
2.16.6 externalAuth override to false
110+
2.16.7 externalAuth override to true
87111

88112
3. examples.js
89113
3.1 connect.js
@@ -5127,6 +5151,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
51275151
255.2.5 change resetStatistics with enableStatistics
51285152
255.2.6 change resetStatistics
51295153
255.2.7 getStatistics
5154+
255.2.8 getStatistics - noneditable properties
51305155
255.3 poolReconfigure JS layer properties
51315156
255.3.1 change queueMax
51325157
255.3.2 change queueTimeout

0 commit comments

Comments
 (0)