How to use database connections pool in Sequelize.js

前端 未结 3 1937
别那么骄傲
别那么骄傲 2020-12-29 22:13

I need some clarification about what the pool is and what it does. The docs say Sequelize will setup a connection pool on initialization so you should ideally only ever crea

相关标签:
3条回答
  • 2020-12-29 22:40

    pool is draining error

    I found this thread in my search for a Sequalize error was giving my node.js app: pool is draining. I could not for the life of me figure it out. So for those who follow in my footsteps:

    The issue was that I was closing the database earlier than I thought I was, with the command sequelize.closeConnections(). For some reason, instead of an error like 'the database has been closed`, it was instead giving the obscure error 'pool is draining'.

    0 讨论(0)
  • 2020-12-29 22:55

    When your application needs to retrieve data from the database, it creates a database connection. Creating this connection involves some overhead of time and machine resources for both your application and the database. Many database libraries and ORM's will try to reuse connections when possible, so that they do not incur the overhead of establishing that DB connection over and over again. The pool is the collection of these saved, reusable connections that, in your case, Sequelize pulls from. Your configuration of

    pool: {
        max: 5,
        min: 0,
        idle: 10000
      }
    

    reflects that your pool should:

    1. Never have more than five open connections (max: 5)
    2. At a minimum, have zero open connections/maintain no minimum number of connections (min: 0)
    3. Remove a connection from the pool after the connection has been idle (not been used) for 10 seconds (idle: 10000)

    tl;dr: Pools are a good thing that help with database and overall application performance, but if you are too aggressive with your pool configuration you may impact that overall performance negatively.

    0 讨论(0)
  • 2020-12-29 22:57

    Seems that you can try to put pool to false to avoid having the pool bing created. Here is the API details table :http://sequelize.readthedocs.org/en/latest/api/sequelize/

    [options.pool={}] Object Should sequelize use a connection pool. Default is true

    0 讨论(0)
提交回复
热议问题