Skip to content

Commit

Permalink
Update upload-sheet-data.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher committed Oct 21, 2024
1 parent 7c0939e commit 082b184
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/api/src/utils/uploads/upload-sheet-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,18 @@ interface UploadTimeSeriesDataProps {
siteTimezone?: boolean;
}

const MEMORY_LIMIT = 2048; // 2GB
const MAX_MEMORY_USAGE_PERCENT = 80; // Adjust this threshold as needed

function checkMemoryUsage() {
const used = memoryUsage().heapUsed / 1024 / 1024;
const total = memoryUsage().heapTotal / 1024 / 1024;
const usagePercent = (used / total) * 100;
const usagePercent = (used / MEMORY_LIMIT) * 100;

if (usagePercent > MAX_MEMORY_USAGE_PERCENT) {
throw new Error(`Memory usage too high: ${usagePercent.toFixed(2)}%`);
console.warn(`Memory usage too high: ${usagePercent.toFixed(2)}%`);
console.warn(`Used: ${used.toFixed(2)}MB, Total: ${total.toFixed(2)}MB`);
// throw new Error(`Memory usage too high: ${usagePercent.toFixed(2)}%`);
}
}

Expand Down

0 comments on commit 082b184

Please sign in to comment.