diff --git a/CHANGES b/CHANGES index 82083fb..229b911 100644 --- a/CHANGES +++ b/CHANGES @@ -1,11 +1,12 @@ Change log ========== -1.2.0 (2020-04-16) +1.2.0 (2020-04-20) ------------------ * Connection re-open after critical server errors * Error code string representation added to error object +* Pool improvements 1.1.0 (2020-04-14) ------------------ diff --git a/lib/wrapper/sapnwrfc-pool.d.ts b/lib/wrapper/sapnwrfc-pool.d.ts index 22e795a..65fa77e 100644 --- a/lib/wrapper/sapnwrfc-pool.d.ts +++ b/lib/wrapper/sapnwrfc-pool.d.ts @@ -8,10 +8,11 @@ export declare class Pool { private __connectionParams; private __poolOptions; private __clientOptions; + private __fillRequests; private __clients; constructor(connectionParams: RfcConnectionParameters, poolOptions?: RfcPoolOptions, clientOptions?: RfcClientOptions); newClient(): Client; - fill(): void; + refill(): void; acquire(): Promise; release(client: Client): Promise; releaseAll(): Promise; diff --git a/lib/wrapper/sapnwrfc-pool.js b/lib/wrapper/sapnwrfc-pool.js index a0ef7df..779d61a 100644 --- a/lib/wrapper/sapnwrfc-pool.js +++ b/lib/wrapper/sapnwrfc-pool.js @@ -11,6 +11,7 @@ class Pool { this.__connectionParams = connectionParams; this.__poolOptions = poolOptions; this.__clientOptions = clientOptions; + this.__fillRequests = 0; this.__clients = { ready: [], active: new Map(), @@ -21,14 +22,20 @@ class Pool { ? new sapnwrfc_client_1.Client(this.__connectionParams, this.__clientOptions) : new sapnwrfc_client_1.Client(this.__connectionParams); } - fill() { + refill() { + if (this.__clients.ready.length + this.__fillRequests >= + this.__poolOptions.min) { + return; + } + this.__fillRequests++; const client = this.newClient(); client.connect((err) => { + this.__fillRequests--; if (util_1.isUndefined(err)) { if (this.__clients.ready.length < this.__poolOptions.min) { this.__clients.ready.unshift(client); if (this.__clients.ready.length < this.__poolOptions.min) - this.fill(); + this.refill(); } else { client.close(() => { }); @@ -43,7 +50,7 @@ class Pool { return new Promise((resolve, reject) => { const client = this.__clients.ready.pop(); if (this.__clients.ready.length < this.__poolOptions.min) - this.fill(); + this.refill(); if (client instanceof sapnwrfc_client_1.Client) { this.__clients.active.set(client.id, client); resolve(client); @@ -70,7 +77,7 @@ class Pool { client.close(() => { this.__clients.active.delete(id); if (this.__clients.ready.length < this.__poolOptions.min) { - this.fill(); + this.refill(); } resolve(id); }); diff --git a/lib/wrapper/sapnwrfc-pool.js.map b/lib/wrapper/sapnwrfc-pool.js.map index 9ceb403..4c11cd3 100644 --- a/lib/wrapper/sapnwrfc-pool.js.map +++ b/lib/wrapper/sapnwrfc-pool.js.map @@ -1 +1 @@ -{"version":3,"file":"sapnwrfc-pool.js","sourceRoot":"","sources":["../../src/ts/wrapper/sapnwrfc-pool.ts"],"names":[],"mappings":";;AAAA,IAAI,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAQzB,0BAAO;AAPhB,uDAI2B;AAC3B,+BAAmC;AASnC,MAAa,IAAI;IAUb,YACI,gBAAyC,EACzC,cAA8B;QAC1B,GAAG,EAAE,CAAC;KAET,EACD,aAAgC;QAEhC,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG;YACb,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,IAAI,GAAG,EAAE;SACpB,CAAC;IACN,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,eAAe;YACvB,CAAC,CAAC,IAAI,wBAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,eAAe,CAAC;YAC3D,CAAC,CAAC,IAAI,wBAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI;QACA,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,kBAAW,CAAC,GAAG,CA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AAE,CAAC;wBAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;wBAClC,OAAO,CAAC,MAAM,CAAC,CAAC;qBACnB;gBACL,CAAC,CAAC,CAAC;aACN;YACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CACpC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;gBACd,MAAM,EAAE,CAAC;gBACT,IAAI,MAAM,KAAK,UAAU,EAAE;oBACvB,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;oBAClC,OAAO,CAAC,MAAM,CAAC,CAAC;iBACnB;YACL,CAAC,CAAC,CACL,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,MAAM;QACN,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI;YAClC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM;YAClC,OAAO,EAAE,IAAI,CAAC,aAAa;SAC9B,CAAC;IACN,CAAC;CACJ;AArID,oBAqIC"} \ No newline at end of file +{"version":3,"file":"sapnwrfc-pool.js","sourceRoot":"","sources":["../../src/ts/wrapper/sapnwrfc-pool.ts"],"names":[],"mappings":";;AAAA,IAAI,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAQzB,0BAAO;AAPhB,uDAI2B;AAC3B,+BAAmC;AASnC,MAAa,IAAI;IAWb,YACI,gBAAyC,EACzC,cAA8B;QAC1B,GAAG,EAAE,CAAC;KAET,EACD,aAAgC;QAEhC,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC;QACrC,IAAI,CA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AAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,MAAM;QACN,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI;YAClC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM;YAClC,OAAO,EAAE,IAAI,CAAC,aAAa;SAC9B,CAAC;IACN,CAAC;CACJ;AAhJD,oBAgJC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fba1547..fd471e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -920,9 +920,9 @@ } }, "@types/node": { - "version": "13.11.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.11.1.tgz", - "integrity": "sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g==", + "version": "13.13.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.0.tgz", + "integrity": "sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==", "dev": true }, "@types/prettier": { diff --git a/package.json b/package.json index d0ff769..df35c51 100755 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "devDependencies": { "@babel/core": "^7.9.0", "@types/bluebird": "^3.5.30", - "@types/node": "^13.11.1", + "@types/node": "^13.13.0", "async": "^3.2.0", "cmake-js": "^6.1.0", "decimal.js": "^10.2.0", diff --git a/src/ts/wrapper/sapnwrfc-pool.ts b/src/ts/wrapper/sapnwrfc-pool.ts index 69adff8..5c1a0fe 100644 --- a/src/ts/wrapper/sapnwrfc-pool.ts +++ b/src/ts/wrapper/sapnwrfc-pool.ts @@ -17,6 +17,7 @@ export class Pool { private __connectionParams: RfcConnectionParameters; private __poolOptions: RfcPoolOptions; private __clientOptions: RfcClientOptions | undefined; + private __fillRequests: number; private __clients: { ready: Array; @@ -34,6 +35,7 @@ export class Pool { this.__connectionParams = connectionParams; this.__poolOptions = poolOptions; this.__clientOptions = clientOptions; + this.__fillRequests = 0; this.__clients = { ready: [], active: new Map(), @@ -46,14 +48,23 @@ export class Pool { : new Client(this.__connectionParams); } - fill() { + refill() { + if ( + this.__clients.ready.length + this.__fillRequests >= + this.__poolOptions.min + ) { + return; + } + + this.__fillRequests++; const client = this.newClient(); client.connect((err) => { + this.__fillRequests--; if (isUndefined(err)) { if (this.__clients.ready.length < this.__poolOptions.min) { this.__clients.ready.unshift(client); if (this.__clients.ready.length < this.__poolOptions.min) - this.fill(); + this.refill(); } else { client.close(() => {}); } @@ -68,7 +79,7 @@ export class Pool { (resolve: (arg: Client) => void, reject: (arg: any) => void) => { const client = this.__clients.ready.pop(); if (this.__clients.ready.length < this.__poolOptions.min) - this.fill(); + this.refill(); if (client instanceof Client) { this.__clients.active.set(client.id, client); resolve(client); @@ -103,7 +114,7 @@ export class Pool { client.close(() => { this.__clients.active.delete(id); if (this.__clients.ready.length < this.__poolOptions.min) { - this.fill(); + this.refill(); } resolve(id); });