Repl maxes out CPU and Memory after a few seconds

My repl maxes out CPU and Memory after a few seconds, I have no idea why. The only file I’ve changed is src/server.js The code I changed is shown below:


https://replit.com/@CameronDick1/pixelbulb-beta

  let cache = {};
  const cacheList = ['ph', 'wp-content/uploads/ph.svg', 'bh', 'bh-2', 'kh', 'wh', 'edit-webpage', 'edit-webpage-2', 'minion-6-beta', 'cmg', 'wu']
  function updatePH() {

    for(let url of cacheList){
      fetch('https://pixelbulb.online/' + url).then(async (e) => {

        const up = await e;
        const bu = await up.arrayBuffer();
        if (!cache[url] || bu != cache[url].content) {
          if (cache !== {}) {
            const n = setInterval(() => {
              updatePH()
            }, 7000)
            setTimeout(() => { clearInterval(n) }, 1000000)
          }
          cache[url] = {content: bu, contentType: up.headers.get('Content-Type') || 'application/octet-stream'};

        }
  
      }).catch(e => console.log(e))
    }
    return;
  }
  setInterval(() => {
    updatePH()
  }, 30000)
  updatePH();

  app.get('/*', async (req, res, next) => {
    const u = new URL(req.originalUrl, 'https://pixelbulb.online');
    const path = req.originalUrl == '/' ? 'ph' : (u.pathname.substring(1, u.pathname.endsWith('/') ? u.pathname.length-1 : undefined));
    console.log(path);
    if(!cache[path]) {res.send('no data'); return};
    try {
        res.setHeader('Content-Type', cache[path].contentType.split(';')[0]);
        res.send(Buffer.from(cache[path].content));
    } catch (e) { console.log(e); res.send(`<script>alert('Something went wrong, you\'ll be redirected to Pixelbulb');location.replace('https://pixelbulb.online/ph')</script>`); }
  })

this is because you are doing a lot of operations and also because replit natively uses like 80% of the CPU to do background tasks and instead of not counting that, they do which is like ;-; why

2 Likes

They pick inefficient LSP servers…

1 Like

yeah but the my big qualm is WHY are they using YOUR CPU if you want to do that, then just make everyone’s CPU 20% of what it is now and then don’t count your native background tasks. This is literally false marketing like: “oh here’s 100 dollars for bank interest except we used 80 dollars to get it

2 Likes

MS literally does the same thing with MS-DOS derivatives afaik. Their programs do whatever they want, and nobody seems to care

1 Like

Hmm, okay. Could I update my code to fix it?

A quote from UMAR on a similar topic:

1 Like

Wait, nice works in repls?

1 Like

Not sure, but UMAR recommended that. Did say it was untested, but it’s worth a shot.

1 Like