Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize: TimeoutError: ResourceRequest timed out

My Express app running on node 6.11 with Sequelize 4.5.0 will sometimes throw TimeoutError: ResourceRequest timed out, on operations that should not be particularly expensive. We're talking 5 rows of writes, each executed individually.

The database is an Amazon RDS MySQL instance, that hasn't shown any problems connecting to our second API that is written in Ruby and is using ActiveRecord as an ORM.

I'm not sure how to begin diagnosing the problem, any ideas on what I should do next?

like image 745
Sam Calvert Avatar asked Aug 21 '17 17:08

Sam Calvert


4 Answers

I faced the same problem with sequelize using querys that consume much time. Based on the github issue (https://github.com/sequelize/sequelize/issues/8133#issuecomment-359993057) the fix for me was increase the aquire time. When i instanciate a new sequelize I do the following:

const sequelize = new Sequelize(
  config.get("dbConfig.dbName"),
  config.get("dbConfig.user"),
  config.get("dbConfig.password"),
  {
    dialect: "mysql",
    operatorsAliases: false,
    host: config.get("dbConfig.host"),
    pool: {
      max: 100,
      min: 0,
      idle: 200000,
      // @note https://github.com/sequelize/sequelize/issues/8133#issuecomment-359993057
      acquire: 1000000,
    }
  }
);
like image 172
Gustavo Emmel Avatar answered Nov 12 '22 03:11

Gustavo Emmel


This solution works for me:

  pool: {
    max: 100,
    min: 0,
    // @note https://github.com/sequelize/sequelize/issues/8133#issuecomment-359993057
    acquire: 100*1000,
  }
like image 43
webolizzer Avatar answered Nov 12 '22 01:11

webolizzer


For those of you still using v4 of Sequelize, this problem may have been fixed by v4.44.1.

See PR: https://github.com/sequelize/sequelize/pull/11140

See Issue: https://github.com/sequelize/sequelize/issues/11139

like image 2
Michael Kaufman Avatar answered Nov 12 '22 03:11

Michael Kaufman


I think I am the best person qualified to answer this question.

This issue has once made my life hell no matter how much I tweaked the configuration.

So there are two solutions to this problem first one is to set the pool config something like this

pool: {
      max: 50,
      min: 0,
      acquire: 1200000,
      idle: 1000000,
    }

again this will solve your problem for now but again when your load increases you will start to get the error again.

Coming back to the second solution you can really look into table schema or queries you are running against the table.if you are getting these issue that means your queries are not optimized which are taking a much longer time than normal The best bet will be to use indexing on the columns and you will never face this issue

like image 1
gaurav Avatar answered Nov 12 '22 03:11

gaurav