Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduced logging + show retries #253

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/procedures/matlab/matlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ const MATLAB = {};
MATLAB.serviceName = "MATLAB";

async function requestWithRetry(url, body, numRetries = 0) {
try {
return await request.post(url, body, {
timeout: 10000,
});
} catch (err) {
if (err.code === "ECONNABORTED" && numRetries > 0) {
return requestWithRetry(url, body, numRetries - 1);
let err = undefined;
for (let attempts = 1; attempts <= 1 + numRetries; ++attempts) {
try {
const res = await request.post(url, body, { timeout: 10000 });
return [res, attempts];
} catch (e) {
err = e;
if (e.code !== "ECONNABORTED") {
break;
}
}
throw err;
}
throw err || Error("no attempts were made");
}

/**
Expand Down Expand Up @@ -94,7 +97,11 @@ MATLAB.imageFromMatrix = async function (matrix) {
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
const [r, g, b, a = 255] = matrix[y][x];
res.setPixelColor(jimp.rgbaToInt(clamp(r), clamp(g), clamp(b), clamp(a)), x, y);
res.setPixelColor(
jimp.rgbaToInt(clamp(r), clamp(g), clamp(b), clamp(a)),
x,
y,
);
}
}
return utils.sendImageBuffer(
Expand Down Expand Up @@ -126,14 +133,16 @@ MATLAB.function = async function (fn, args = [], numReturnValues = 1) {
// - start
// - batch requests while starting
// - send requests on start
// - keepWarm

const startTime = Date.now();
const resp = await requestWithRetry(`${MATLAB_URL}/feval-fast`, body, 5);
const [resp, attempts] = await requestWithRetry(
`${MATLAB_URL}/feval-fast`,
body,
5,
);
const duration = Date.now() - startTime;
logger.info(
`${duration} body: ${JSON.stringify(body)} response: ${
JSON.stringify(resp.data)
}`,
`matlab response -- duration: ${duration / 1000}s, attempts: ${attempts}`,
);

const results = resp.data.FEvalResponse;
Expand Down