From 1431af786f4d2728bad4132d505758144798516b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 21 Jan 2023 10:30:16 +0100 Subject: [PATCH] Evaluate OCPP messages buffer flush performance MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 11 +++++++++-- src/charging-station/ocpp/OCPPRequestService.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 547a4f36..e1d25740 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -768,9 +768,16 @@ export default class ChargingStation { private flushMessageBuffer(): void { if (this.messageBuffer.size > 0) { this.messageBuffer.forEach((message) => { - // TODO: evaluate the need to track performance - this.wsConnection.send(message); + let beginId: string; + let commandName: RequestCommand; const [messageType] = JSON.parse(message) as OutgoingRequest | Response | ErrorResponse; + const isRequest = messageType === MessageType.CALL_MESSAGE; + if (isRequest) { + [, , commandName] = JSON.parse(message) as OutgoingRequest; + beginId = PerformanceStatistics.beginMeasure(commandName); + } + this.wsConnection.send(message); + isRequest && PerformanceStatistics.endMeasure(commandName, beginId); logger.debug( `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString( messageType diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 6ce5e3a7..13cb1707 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -247,7 +247,7 @@ export default abstract class OCPPRequestService { // Check if wsConnection opened const wsOpened = chargingStation.isWebSocketConnectionOpened() === true; if (wsOpened) { - const beginId = PerformanceStatistics.beginMeasure(commandName as string); + const beginId = PerformanceStatistics.beginMeasure(commandName); try { chargingStation.wsConnection.send(messageToSend); logger.debug( @@ -264,7 +264,7 @@ export default abstract class OCPPRequestService { ); sendError = true; } - PerformanceStatistics.endMeasure(commandName as string, beginId); + PerformanceStatistics.endMeasure(commandName, beginId); } const wsClosedOrErrored = !wsOpened || sendError === true; if (wsClosedOrErrored && params.skipBufferingOnError === false) { -- 2.34.1