title: My google cloud functions take longer and longer each call
body: <p>Here's a patebin of the code (password isn't real): <a href="https://pastebin.com/Br37dX8r" rel="nofollow noreferrer">https://pastebin.com/Br37dX8r</a></p>
  <pre><code>const functions = require(&quot;firebase-functions&quot;);
  const express = require(&quot;express&quot;);
  const redis = require(&quot;redis&quot;);
  const regionInfo = require(&quot;./regionInfo.json&quot;);
  
  const app = express();
  const client = redis.createClient({
      database: 0,
      password: &quot;hunter123&quot;,
      url: &quot;redis://database.skeld.net&quot;,
      socket: 6379,
   });
  
  app.get(&quot;/games&quot;, async (request, response) =&gt; {
      console.log(&quot;/games request&quot;);
      await client.connect();
      const codes = await client.sMembers(&quot;skeldsync.games&quot;);
      response.set(&quot;Cache-Control&quot;, &quot;public, max-age=10, s-maxage=20&quot;);
      response.setHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
      var lobbyInfos = new Array();
      for (const idx in codes) {
          const code = codes[idx];
          const lobbyInfo = await client.hGetAll(&quot;ImpostorRedis&quot; + code);
          if (lobbyInfo.in_progress == &quot;true&quot;) continue;
          lobbyInfos.push(lobbyInfo.lobby_data);
      }
      var result = `${JSON.stringify(lobbyInfos)}`;
      response.send(result);
      console.log(&quot;Lobby infos length: &quot; + lobbyInfos.length);
      await client.disconnect();
  });
   
  app.get(&quot;/playercount&quot;, async (request, response) =&gt; {
      console.log(&quot;/playercount request&quot;);
      await client.connect();
      const codes = await client.sMembers(&quot;skeldsync.games&quot;);
      response.set(&quot;Cache-Control&quot;, &quot;public, max-age=5, s-maxage=10&quot;);
      response.setHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
      var totalPlayers = 0;
      for (const idx in codes) {
          const code = codes[idx];
          const str = await client.hGet(&quot;ImpostorRedis&quot; + code, &quot;player_count&quot;);
          if (str == null) continue;
          const playerCount = Number.parseInt(str);
          totalPlayers += playerCount;
      }
      var result = `${totalPlayers}`;
      response.send(result);
      console.log(&quot;Total players: &quot; + result);
      await client.disconnect();
  });
   
  app.get(&quot;/regionInfo&quot;, async (request, response) =&gt; {
      console.log(&quot;/regionInfo request&quot;);
      response.set(&quot;Cache-Control&quot;, &quot;public, max-age=3600, s-maxage=3600&quot;);
      response.send(regionInfo);
  });
   
  app.get(&quot;/ip&quot;, async (request, response) =&gt; {
      console.log(&quot;/ip request&quot;);
      response.set(&quot;Cache-Control&quot;, &quot;public, max-age=3600, s-maxage=3600&quot;);
      response.send(regionInfo.Regions[0].Servers[0].Ip);
  });
   
  app.get(&quot;/deeplink&quot;, async (request, response) =&gt; {
      console.log(&quot;/deeplink request&quot;);
      response.setHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
      response.set(&quot;Cache-Control&quot;, &quot;public, max-age=3600, s-maxage=3600&quot;);
      response.send(
          `amongus://init\?servername=&lt;color=\&quot;orange\&quot;&gt;skeld.net\&amp;serverport=22023\&amp;serverip=${regionInfo.Regions[0].Servers[0].Ip}\&amp;usedtls=false`
      );
  });
   
  exports.app = functions.https.onRequest(app);
  </code></pre>
  <p>I know it's not the cleanest code. That is okay, it's a simple and small API.
  Issue is, that each time an API request is made it takes longer and longer. Starting at 100ms but after a few thousand calls by my users it takes upwards of 12000ms per call.</p>
  <p>I'm really not sure why this is happening.</p>