Evaluate OCPP messages buffer flush performance
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 21 Jan 2023 09:30:16 +0000 (10:30 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 21 Jan 2023 09:30:16 +0000 (10:30 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPRequestService.ts

index 547a4f3693321bf271d23cdae07c6cb51df01876..e1d25740a7b3522b2ee41a4e8a3e95bf8247de79 100644 (file)
@@ -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
index 6ce5e3a7f6d27e9f5447073dfe36ccf7abbda686..13cb170789f502fce73c4e6847b9e45f12fad6da 100644 (file)
@@ -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) {