0

I use Rails 5.1.4, Sequel 5.9.0, Postgre, rack-mini-profiler (the latest), sequel-rails 1.0.1.

I'm trying to figure out why my application is slow. Here's what I found.

I made a simple query to get posts using

@posts = Post.all

and got ~150.

And I have a partial to render it. This is simplified:

<% @posts.each do |post| %>
  <%= post.title %>
  <%= post.body %>
<% end %>

When I looked in rack-mini-profiler's log, I saw

SELECT NULL; 

requests which slows rendering, but if I change the . method to :[]:

<% @posts.each do |post| %>
  <%= post[:title] %>
  <%= post[:body] %>
<% end %>

the NULL queries disappear and rendering becomes much faster. (Both title and body are fields in my DB, nothing else.)

Why? Is this the thing I need to know about Sequel? I should not use instance.method in the future in that cases, or am I missing something?

When I tried the request from the console, I got:

> Post.first
D, [2018-06-09T22:46:41.277269 #96772] DEBUG -- : (0.001008s) SELECT NULL
D, [2018-06-09T22:46:41.277952 #96772] DEBUG -- : (0.000362s) SELECT * FROM "posts" LIMIT 1

What is the first phantom request? How can I debug and remove it?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
okliv
  • 3,909
  • 30
  • 47
  • The plugin is providing a heart-beat to make sure the database connection is alive. DBMs often close long-running connections to preserve available logins; When that happens your app will break because the connection is gone, so the app periodically checks, keeping the app running. You can reconfigure your DBM to not do that, but in general it's a bad idea as you can consume all your connections, which can be bad. It's a good thing to have the heart-beat, and a `select null` takes no time to process; It's a very standard way of handling this. – the Tin Man Feb 09 '20 at 20:05

1 Answers1

0

Finally, I found the problem:

it was a :connection_validator plugin.

Bypass this plugin unless you really-really need it!

okliv
  • 3,909
  • 30
  • 47
  • Don't bypass it. Learn what it's providing and then decide if you don't want it. The capability it provides is very useful and doesn't cause any slow-down or have negative results in its default settings or if you have configured it correctly from its defaults. – the Tin Man Feb 09 '20 at 20:07