Skip to content

Commit

Permalink
Merge pull request #4141 from sap-labs-france/master-qa
Browse files Browse the repository at this point in the history
Version 2.7.5 - Performance Improvements
  • Loading branch information
Claude ROSSI authored Mar 7, 2023
2 parents f47020d + 13c12cd commit 13a3bd4
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 50 deletions.
24 changes: 21 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"name": "vscode-jest-tests",
Expand Down Expand Up @@ -100,9 +101,26 @@
],
"stopOnEntry": true
},



{
"name": "start:dev:debug:batch",
"type": "pwa-node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"start:dev:debug:batch"
],
"sourceMaps": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"skipFiles": [
"<node_internals>/**"
],
"stopOnEntry": true
},
{
"name": "Debug Tests 'createContext'",
"type": "pwa-node",
Expand Down
24 changes: 24 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
apps: [{
env: {
NODE_ENV: "development",
SERVER_ROLE: "ocppj"
},
name: "pm2 - OCPP",
script: "./dist/start.js"
}, {
env: {
NODE_ENV: "development",
SERVER_ROLE: "rest"
},
name: "pm2 - REST",
script: "./dist/start.js"
}, {
env: {
NODE_ENV: "development",
SERVER_ROLE: "batch"
},
name: "pm2 - BATCH",
script: "./dist/start.js"
}]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"start:dev:debug": "npm version && cross-env NODE_ENV=development ts-node-dev --inspect --files --max-old-space-size=4096 -- src/start.ts",
"start:dev:debug:ocppj": "npm version && cross-env SERVER_ROLE=ocppj NODE_ENV=development ts-node-dev --inspect --files --max-old-space-size=4096 -- src/start.ts",
"start:dev:debug:rest": "npm version && cross-env SERVER_ROLE=rest NODE_ENV=development ts-node-dev --inspect --files --max-old-space-size=4096 -- src/start.ts",
"start:dev:debug:batch": "npm version && cross-env SERVER_ROLE=batch NODE_ENV=development ts-node-dev --inspect --files --max-old-space-size=4096 -- src/start.ts",
"start:dev:debug:nodemon": "npm version && nodemon --exec \"ts-node --files\" src/start.ts 9229",
"start:dev:nodemon": "npm version && nodemon --exec \"ts-node --files\" src/start.ts",
"start:dev:prof": "npm version && cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" NODE_ENV=development node -r source-map-support/register --prof -- dist/start.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio
this.tenant, { chargingStationIDs: chargingStationIDs, profilePurposeType: ChargingProfilePurposeType.TX_PROFILE }, Constants.DB_PARAMS_MAX_LIMIT);
const currentChargingProfiles = currentChargingProfilesResponse.result;
// Get all transactions of the site areas
const transactions = await TransactionStorage.getTransactions(this.tenant, { transactionIDs, withCar: true }, Constants.DB_PARAMS_MAX_LIMIT);
const transactions = await TransactionStorage.getTransactions(this.tenant, { transactionIDs, withSmartChargingData: true }, Constants.DB_PARAMS_MAX_LIMIT);
// Build request
const request = await this.buildOptimizerRequest(rootSiteArea, excludedChargingStations, false, currentChargingProfiles, transactions.result);
// Call optimizer
Expand Down
68 changes: 37 additions & 31 deletions src/scheduler/tasks/CheckChargingStationTemplateTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,45 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas

private async applyTemplateToChargingStations(tenant: Tenant) {
let updated = 0;
// Bypass perf tenant
if (tenant.subdomain === 'testperf') {
await Logging.logWarning({
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'applyTemplateToChargingStations',
message: `Bypassed tenant ${Utils.buildTenantName(tenant)})`
// Prepare pagination
const limit = Constants.BATCH_PAGE_SIZE; // Avoid loading too much data in one shot
const sort = null; // No sort
let skip = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
// Get the charging stations
const chargingStations = await ChargingStationStorage.getChargingStations(tenant, {
issuer: true,
manualConfiguration: false, // template cannot be applied when a manual configuration is being used
// withSiteArea: true, // Site area data is loaded only when necessary
}, {
limit, skip, sort
});
return;
}
// Get the charging stations
const chargingStations = await ChargingStationStorage.getChargingStations(tenant, {
issuer: true, withSiteArea: true
}, Constants.DB_PARAMS_MAX_LIMIT);
// Update
for (const chargingStation of chargingStations.result) {
try {
// Apply template
const chargingStationTemplateUpdateResult = await OCPPUtils.checkAndApplyTemplateToChargingStation(tenant, chargingStation);
// Save
if (chargingStationTemplateUpdateResult.chargingStationUpdated) {
await ChargingStationStorage.saveChargingStation(tenant, chargingStation);
updated++;
if (Utils.isEmptyArray(chargingStations.result)) {
break;
}
// Increment skip for next round
skip += limit;
// Update
for (const chargingStation of chargingStations.result) {
try {
// Apply template
const chargingStationTemplateUpdateResult = await OCPPUtils.checkAndApplyTemplateToChargingStation(tenant, chargingStation);
// Save
if (chargingStationTemplateUpdateResult.chargingStationUpdated) {
await ChargingStationStorage.saveChargingStation(tenant, chargingStation);
updated++;
}
} catch (error) {
await Logging.logError({
...LoggingHelper.getChargingStationProperties(chargingStation),
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'applyTemplateToChargingStations',
message: `Template update error in Tenant ${Utils.buildTenantName(tenant)}): ${error.message as string}`,
detailedMessages: { error: error.stack }
});
}
} catch (error) {
await Logging.logError({
...LoggingHelper.getChargingStationProperties(chargingStation),
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'applyTemplateToChargingStations',
message: `Template update error in Tenant ${Utils.buildTenantName(tenant)}): ${error.message as string}`,
detailedMessages: { error: error.stack }
});
}
}
if (updated > 0) {
Expand Down
24 changes: 15 additions & 9 deletions src/server/ocpp/utils/OCPPUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1530,13 +1530,12 @@ export default class OCPPUtils {
if (chargingStationTemplate) {
// Already updated?
if (chargingStation.templateHash !== chargingStationTemplate.hash) {
await Logging.logInfo({
await Logging.logDebug({
...LoggingHelper.getChargingStationProperties(chargingStation),
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'enrichChargingStationWithTemplate',
message: `Template ID '${chargingStationTemplate.id}' is been applied...`,
detailedMessages: { chargingStationTemplate, chargingStation }
message: `Template ID '${chargingStationTemplate.id}' is being applied...`
});
// Check Technical
templateUpdateResult.technicalUpdated =
Expand All @@ -1559,16 +1558,21 @@ export default class OCPPUtils {
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'enrichChargingStationWithTemplate',
message: `Template ID '${chargingStationTemplate.id}' has been applied with success`,
detailedMessages: { templateUpdateResult, chargingStationTemplate, chargingStation }
detailedMessages: {
templateUpdateResult,
templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate),
}
});
} else {
await Logging.logInfo({
await Logging.logDebug({
...LoggingHelper.getChargingStationProperties(chargingStation),
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'enrichChargingStationWithTemplate',
message: `Template ID '${chargingStationTemplate.id}' has already been applied`,
detailedMessages: { chargingStationTemplate, chargingStation }
detailedMessages: {
templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate)
}
});
}
// Master/Slave: always override the charge point
Expand All @@ -1583,10 +1587,12 @@ export default class OCPPUtils {
tenantID: tenant.id,
action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE,
module: MODULE_NAME, method: 'enrichChargingStationWithTemplate',
message: 'No Template has been found for this Charging Station',
detailedMessages: { chargingStation }
message: 'No template has been found',
detailedMessages: {
chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation)
}
});
chargingStation.manualConfiguration = true;
chargingStation.manualConfiguration = true; // To be clarified! - Why is this changed here???
}
return templateUpdateResult;
}
Expand Down
8 changes: 6 additions & 2 deletions src/storage/mongodb/ChargingStationStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class ChargingStationStorage {
connectorStatuses?: ChargePointStatus[]; connectorTypes?: ConnectorType[]; statusChangedBefore?: Date; withSiteArea?: boolean; withUser?: boolean;
ocpiEvseUid?: string; ocpiLocationID?: string; oicpEvseID?: string;
siteIDs?: string[]; companyIDs?: string[]; withSite?: boolean; includeDeleted?: boolean; offlineSince?: Date; issuer?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; public?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; public?: boolean; manualConfiguration?: boolean;
},
dbParams: DbParams, projectFields?: string[]): Promise<ChargingStationDataResult> {
const startTime = Logging.traceDatabaseRequestStart();
Expand Down Expand Up @@ -180,9 +180,13 @@ export default class ChargingStationStorage {
filters.deleted = { '$ne': true };
}
// Public Charging Stations
if (Utils.objectHasProperty(params, 'public') && Utils.isBoolean(params.public)) {
if (Utils.isBoolean(params.public)) {
filters.public = params.public;
}
// Charging Station
if (Utils.isBoolean(params.manualConfiguration)) {
filters.manualConfiguration = params.manualConfiguration;
}
// Charging Stations
if (!Utils.isEmptyArray(params.chargingStationIDs)) {
filters._id = {
Expand Down
13 changes: 12 additions & 1 deletion src/storage/mongodb/TransactionStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export default class TransactionStorage {
ocpiSessionID?: string; ocpiAuthorizationID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean; oicpSessionID?: string; withSite?: boolean; withSiteArea?: boolean; withCompany?: boolean;
statistics?: TransactionStatisticsType; refundStatus?: RefundStatus[]; withTag?: boolean; hasUserID?: boolean; withUser?: boolean; withCar?: boolean;
transactionsToStop?: boolean; siteOwnerIDs?: string[];
transactionsToStop?: boolean; siteOwnerIDs?: string[]; withSmartChargingData?: boolean
},
dbParams: DbParams, projectFields?: string[]): Promise<TransactionDataResult> {
const startTime = Logging.traceDatabaseRequestStart();
Expand Down Expand Up @@ -753,6 +753,17 @@ export default class TransactionStorage {
foreignField: '_id', oneToOneCardinality: true
});
}
// Smart Charging Data
if (params.withSmartChargingData) {
DatabaseUtils.pushCarLookupInAggregation({
tenantID: tenant.id, aggregation: aggregation, asField: 'car', localField: 'carID',
foreignField: '_id', oneToOneCardinality: true, oneToOneCardinalityNotNull: false, projectFields:['converter.amperagePerPhase']
});
DatabaseUtils.pushCarCatalogLookupInAggregation({
tenantID: Constants.DEFAULT_TENANT_ID, aggregation: aggregation, asField: 'carCatalog', localField: 'carCatalogID',
foreignField: '_id', oneToOneCardinality: true, projectFields:['fastChargePowerMax', 'batteryCapacityFull']
});
}
// Rename ID
DatabaseUtils.pushRenameDatabaseIDToNumber(aggregation);
// Convert Object ID to string
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default class Constants {
public static readonly EXPORT_PAGE_SIZE = 1000;
public static readonly EXPORT_RECORD_MAX_COUNT = 100000;
public static readonly IMPORT_PAGE_SIZE = 1000;
public static readonly IMPORT_BATCH_INSERT_SIZE = 250;
public static readonly BATCH_PAGE_SIZE = 1000;
public static readonly IMPORT_BATCH_INSERT_SIZE = 256;
public static readonly BATCH_PAGE_SIZE = 256;

public static readonly SFDP_LATTITUDE = 43.585784;
public static readonly SFDP_LONGITUDE = 7.0377592;
Expand Down
21 changes: 20 additions & 1 deletion src/utils/LoggingHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ChargingStation, { ChargingStationTemplate } from '../types/ChargingStation';

import Asset from '../types/Asset';
import { Car } from '../types/Car';
import ChargingStation from '../types/ChargingStation';
import { PricingContext } from '../types/Pricing';
import RegistrationToken from '../types/RegistrationToken';
import Site from '../types/Site';
Expand Down Expand Up @@ -110,4 +111,22 @@ export default class LoggingHelper {
stopTimestamp: transaction?.stop?.timestamp
};
}

public static shrinkChargingStationProperties(chargingStation: ChargingStation) {
return {
id: chargingStation?.id,
chargePointVendor: chargingStation?.chargePointVendor,
chargePointModel: chargingStation?.chargePointModel,
chargePointSerialNumber: chargingStation?.chargePointSerialNumber,
firmwareVersion: chargingStation?.firmwareVersion,
};
}

public static shrinkTemplateProperties(templateContainer: ChargingStationTemplate) {
return {
id: templateContainer?.id,
chargePointVendor: templateContainer?.template?.chargePointVendor,
extraFilters: templateContainer?.template?.extraFilters,
};
}
}

0 comments on commit 13a3bd4

Please sign in to comment.