Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
MySQL queries taking longer when response is empty

I'm building my first website using Node.js as the webserver and fetch to request to the server. When the MySQL database is run from localhost, my requests take less than 30ms each and there are no issues with the webpage. However, when the server is hosted somewhere else, I get very long response times ONLY when the resulting data from the query returns '[].' I'm trying to figure out why this would be the case only when requesting from a non-localhost database (or why this is happening in general).

See the difference in response times between these two links:

{ link removed }

{ link removed }

You'll see that the one which returns '[]' takes significantly longer than the other.

Here's the serverside code used:

    router.get('/getgames/:matchid/:season', (req, res) => {
    let sql = `SELECT * FROM games WHERE match_id='${req.params.matchid}' AND season='${req.params.season}'`;
    let query = db.query(sql, (err, result) => {
        if (err) throw err;
        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end(JSON.stringify(result));
    });
});

I don't think it's necessary to include the clientside code because the request takes just as long when it's put into the URL bar.

It's also important to note that the tables being accessed have less than 10 rows, so I don't think indexing/posting my explains would actually fix this problem (or would it??).

Edit: I've added a covering index to the 'games' table, and the query is still just as slow.

Thanks for your help.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

For some reason I'm not sure of, node seems to be waiting for keep-alive to be closed before sending that empty array body. Disabling keep-alive mitigates this issue, see https://nodejs.org/api/http.html#http_server_keepalivetimeout (the default timeout of keep-alive is 5s)

I suppose having a longer body overcomes this issue, that's why it's returning immediately for sets with actual sql results.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda