Skip to content

Use lazy connect and let server disconnect on inactivity #30

@zuiderkwast

Description

@zuiderkwast

Currently, when you start an application using MySQL/OTP+Poolboy, you immediately see a number of connections to the DB server. Most of them are idle.

This is an idea of reducing the number of connections to the server to what is actually needed. With MySQL/OTP 1.6.0, no error is logged when the server disconnects. This, with the new lazy connect strategy, allows us to have a more server-friendly approach:

  • Change poolboy strategy to LIFO (which is the default for poolboy, so we just remove the {strategy, fifo} option)
  • Turn off keep-alive
  • Set connect strategy to lazy

The scenario would look like this:

  1. Poolboy starts starts a pool of workers. The workers don't connect to the DB yet.
  2. When a worker is used and a query is executed, the worker connects to the DB.
  3. On load spikes, more workers are used, thus more workers connect to the DB.
  4. When the load goes down, the last connected nodes will be disconnected because of inactivity. (The timeout can be set on the server side.) This causes poolboy to restart the worker, but it will be started in disconnected (lazy connect) state.

I suggest we make these options the default in this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions