Search code examples
mysqlrubysinatrasequel

Sequel + Sinatra + Phusion Passenger + MySQL Connection Management


We are using Sinatra and Sequel for a small API implementation. The problem we have however is that on every page request Sequel opens new connections to MySQL, and keeps them open till they timeout, or you restart Apache.

There's not a lot of documentation on how to reuse connections, so any help, explanations, and/or pointers in the right direction would help.


Solution

  • We figured out what we were doing wrong. It was rather stupid, we initialized Sequel in a before filter in Sinatra.

    So instead we do:

    DB = Sequel.mysql("...")
    

    Then we simply use the DB constant to use Sequel.