Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1618

Memory usage with node js and chunk

$
0
0

I try extract data in chunks in order to reduce memory usage.The original file size is 2.24MBThe data size that I need to resolve is 0.2mbBut no matter what I do it seems like measuring the concatenated data is almost 2.2MB.

Here my code

function foo(url,sectionToWatchStart,sectionToWatchEnd ) {  let isDataSectionFound = false;  return new Promise((resolve, reject) => {    let buffer= "";    https      .get(url, function (response) {        response.on("data", function (chunk) {          if (chunk.includes(sectionToWatchStart)) isDataSectionFound = true;          if (isDataSectionFound) {            buffer += chunk;            if (chunk.includes(sectionToWatchEnd)) {              isDataSectionFound = false;            }          }        });        response.on("end", function () {          resolve(buffer); // the measure size of buffer variable is just 0.19MB        });      })      .on("error", function (error) {        console.error(error);        reject();      });  });}
// Util Func to measure the size:const mesurMemory = async () => {  const initialMemoryUsage = process.memoryUsage().heapUsed;  const res = await foo();  const finalMemoryUsage = process.memoryUsage().heapUsed;  const memoryUsageForCode = finalMemoryUsage - initialMemoryUsage;  console.log(`Memory usage for code: ${memoryUsageForCode / (1024 * 1024)}MB`);};

So as I said , the file size is 2.24MB and the buffer size is just 0.19MB , why the measure func show usage os 2.2MB


Viewing all articles
Browse latest Browse all 1618

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>