On Monday, November 6, 2017 at 12:18:13 PM UTC+1, [email protected] wrote:
>
> Hi everyone, 
> I'm currently trying to use the connection_validator extension in a way 
> that it validates the connections on every checkout. While I was reading 
> the docs about this extension, I stumbled on this:
>
> Note that if you set the timeout to validate connections on every 
>> checkout, you should probably manually control connection checkouts on a 
>> coarse basis, using Database#synchronize. In a web application, the optimal 
>> place for that would be a rack middleware.
>
>
>  I could not understand exactly what "manually control the connection 
> checkouts on a coarse basis" is supposed to mean. Maybe someone here can 
> help me understand this operation, and why it helps to prevent performance 
> issues on this case?
>

If you don't do this, and you set the validation timeout to -1, every time 
you checkout a connection, it will run a query to see if the connection is 
still active.  Even some simple things like correctly escaping string 
literals can require connection checkouts, which can result in a major 
slowdown.

A coarse checkout would be:

DB.synchronize do
  # your code here
end

In terms of a rack middleware, something like:

class CoarseCheckout
  def initialize(app, db)
    @app  = app
    @db = db
  end
  def call(env)
    db.synchronize{@app.call(env)}
  end
end

use CoarseCheckout, DB

Hopefully that answers your question.  If you have more questions, please 
ask.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to