From: Jérôme Benoit Date: Sat, 21 Jan 2023 09:30:16 +0000 (+0100) Subject: Evaluate OCPP messages buffer flush performance X-Git-Tag: v1.1.92~30 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1431af786f4d2728bad4132d505758144798516b;p=e-mobility-charging-stations-simulator.git Evaluate OCPP messages buffer flush performance Signed-off-by: Jérôme Benoit --- 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) {