Skip to content

Commit

Permalink
Fb/concurrency polish (#51)
Browse files Browse the repository at this point in the history
* increase default concurrency for cds and service-manager from 5 to 10

* add user level control for cds and hdi concurrency with env variables
  • Loading branch information
rlindner81 authored Dec 21, 2023
1 parent 20a95a9 commit 2401228
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/shared/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const ENV = Object.freeze({
HDI_APP: "MTX_HDI_APP",
SERVER_APP: "MTX_SRV_APP",
APP_SUFFIX: "MTX_APP_SUFFIX",
CDS_CONCURRENCY: "MTX_CDS_CONCURRENCY",
HDI_CONCURRENCY: "MTX_HDI_CONCURRENCY",
});

const isUUID = (input) =>
Expand Down
46 changes: 23 additions & 23 deletions src/submodules/capMultitenancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { promisify } = require("util");
const { writeFile } = require("fs");
const {
ENV,
isUUID,
isDashedWord,
sleep,
Expand All @@ -16,11 +17,14 @@ const {
const { assert, assertAll } = require("../shared/error");
const { request, requestTry } = require("../shared/request");

const writeFileAsync = promisify(writeFile);
const POLL_FREQUENCY = 15000;
const CDS_UPGRADE_APP_INSTANCE = 0;
const CDS_OFFBOARD_CONCURRENCY = 5;
const CDS_UPGRADE_TASK_STATUS_CONCURRENCY = 5;
const CDS_REQUEST_CONCURRENCY_FALLBACK = 10;

const writeFileAsync = promisify(writeFile);
const cdsRequestConcurrency = process.env[ENV.CDS_CONCURRENCY]
? parseInt(process.env[ENV.CDS_CONCURRENCY])
: CDS_REQUEST_CONCURRENCY_FALLBACK;

const _isMtxs = async (context) => {
if (_isMtxs._result === undefined) {
Expand Down Expand Up @@ -189,25 +193,21 @@ const _cdsUpgrade = async (
assert(tenants, "no tenants found in response for upgrade\n%j", upgradeResponseData);
let allSuccess = true;
const table = [["tenantId", "status", "message"]].concat(
await limiter(
CDS_UPGRADE_TASK_STATUS_CONCURRENCY,
Object.entries(tenants),
async ([tenantId, { ID: taskId }]) => {
const pollTaskResponse = await requestTry({
checkStatus: false,
url: cfRouteUrl,
pathname: `/-/cds/jobs/pollTask(ID='${taskId}')`,
auth: { token: await context.getCachedUaaToken() },
headers: {
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`,
},
});
const pollTaskResponseData = await _safeMaterializeJson(pollTaskResponse, "poll task");
const { status, error } = pollTaskResponseData || {};
allSuccess &= status && !error;
return [tenantId, status, error || ""];
}
)
await limiter(cdsRequestConcurrency, Object.entries(tenants), async ([tenantId, { ID: taskId }]) => {
const pollTaskResponse = await requestTry({
checkStatus: false,
url: cfRouteUrl,
pathname: `/-/cds/jobs/pollTask(ID='${taskId}')`,
auth: { token: await context.getCachedUaaToken() },
headers: {
"X-Cf-App-Instance": `${cfAppGuid}:${appInstance}`,
},
});
const pollTaskResponseData = await _safeMaterializeJson(pollTaskResponse, "poll task");
const { status, error } = pollTaskResponseData || {};
allSuccess &= status && !error;
return [tenantId, status, error || ""];
})
);
console.log(tableList(table) + "\n");
assert(allSuccess, "upgrade tenant failed");
Expand Down Expand Up @@ -296,7 +296,7 @@ const cdsOffboardTenant = async (context, [tenantId]) => {
const cdsOffboardAll = async (context) => {
const tenants = await _cdsTenants(context);
await limiter(
CDS_OFFBOARD_CONCURRENCY,
cdsRequestConcurrency,
tenants,
async ({ subscribedTenantId }) => await _cdsOffboard(context, subscribedTenantId)
);
Expand Down
11 changes: 8 additions & 3 deletions src/submodules/hanaManagement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const {
ENV,
tableList,
isPortFree,
formatTimestampsWithRelativeDays,
Expand All @@ -15,10 +16,14 @@ const { request } = require("../shared/request");

const TUNNEL_LOCAL_PORT = 30015;
const HIDDEN_PASSWORD_TEXT = "*** show with --reveal ***";
const SERVICE_MANAGER_CONCURRENCY = 5;
const SERVICE_MANAGER_REQUEST_CONCURRENCY_FALLBACK = 10;
const SERVICE_MANAGER_IDEAL_BINDING_COUNT = 1;
const SENSITIVE_CREDENTIAL_FIELDS = ["password", "hdi_password"];

const hdiRequestConcurrency = process.env[ENV.HDI_CONCURRENCY]
? parseInt(process.env[ENV.HDI_CONCURRENCY])
: SERVICE_MANAGER_REQUEST_CONCURRENCY_FALLBACK;

const isValidTenantId = (input) => input && /^[0-9a-z-_/]+$/i.test(input);

const compareForInstanceManagerTenantId = compareFor((a) => a.tenant_id.toUpperCase());
Expand Down Expand Up @@ -246,7 +251,7 @@ const _hdiRebindAllServiceManager = async (context, parameters) => {
console.log("rebinding tenants %s", tenantIds.join(", "));

await limiter(
SERVICE_MANAGER_CONCURRENCY,
hdiRequestConcurrency,
bindings,
async (binding) => await _hdiRebindBindingServiceManager(sm_url, token, binding, { parameters })
);
Expand Down Expand Up @@ -298,7 +303,7 @@ const _hdiRepairBindingsServiceManager = async (context, parameters) => {
}
}

await limiter(SERVICE_MANAGER_CONCURRENCY, changes, async (fn) => await fn());
await limiter(hdiRequestConcurrency, changes, async (fn) => await fn());
changes.length === 0 && console.log("found exactly one binding for %i instances, all is well", instances.length);
};

Expand Down

0 comments on commit 2401228

Please sign in to comment.