queries taking time inside `mon_synchronize`

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

queries taking time inside `mon_synchronize`

Thushara Wijeratna
Hi All,

I have a Rails app (rails version 5.2.4.1 / ruby 2.6.3) that makes queries to a postgres database using ActiveRecord.
I want to reduce query latency.

I'm using NewRelic to understand what the slow queries are, and I see pretty much each one of them is spending time inside the `mon_synchronize` method in monitor.rb

I'm attaching a few screenshots from NewRelic.

My question is - what is the reason ActiveRecord is taking this lock? Is there anything I can do to get a better response from the queries.

The database itself is pretty small - thousands of records.

thanks,
thushara


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com.

Screen Shot 2020-02-25 at 9.42.14 AM.png (200K) Download Attachment
Screen Shot 2020-02-25 at 9.43.14 AM.png (180K) Download Attachment
Screen Shot 2020-02-25 at 9.46.06 AM.png (47K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: queries taking time inside `mon_synchronize`

Josh Brody
Hi Thushara,

Just to double-check: Is your database indexed correctly? Have you tried plugging in something like lol_dba gem to spot missing indexes?

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Thushara Wijeratna <[hidden email]> wrote:


Hi All,

I have a Rails app (rails version 5.2.4.1 / ruby 2.6.3) that makes queries to a postgres database using ActiveRecord.
I want to reduce query latency.

I'm using NewRelic to understand what the slow queries are, and I see pretty much each one of them is spending time inside the `mon_synchronize` method in monitor.rb

I'm attaching a few screenshots from NewRelic.

My question is - what is the reason ActiveRecord is taking this lock? Is there anything I can do to get a better response from the queries.

The database itself is pretty small - thousands of records.

thanks,
thushara


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com.
<Screen Shot 2020-02-25 at 9.42.14 AM.png>
<Screen Shot 2020-02-25 at 9.43.14 AM.png>
<Screen Shot 2020-02-25 at 9.46.06 AM.png>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/D86FF58A-0793-4A68-93C5-DDEA4317F165%40josh.mn.
Reply | Threaded
Open this post in threaded view
|

Re: queries taking time inside `mon_synchronize`

Thushara Wijeratna
Yes - the indexes are there. Most times, postgres doesn't use them as it is faster to just read the rows from the table (vs going back to the table again). I've seen this to be the case unless the tables are large.
Also, it is generally pretty fast - but there is this occasional slow down.

On Tuesday, February 25, 2020 at 8:31:11 PM UTC-8, Josh Brody wrote:
Hi Thushara,

Just to double-check: Is your database indexed correctly? Have you tried plugging in something like lol_dba gem to spot missing indexes?

Sent from my iPhone

On Feb 25, 2020, at 10:21 PM, Thushara Wijeratna <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="gsgz-G85CAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">thu...@...> wrote:


Hi All,

I have a Rails app (rails version 5.2.4.1 / ruby 2.6.3) that makes queries to a postgres database using ActiveRecord.
I want to reduce query latency.

I'm using NewRelic to understand what the slow queries are, and I see pretty much each one of them is spending time inside the `mon_synchronize` method in monitor.rb
<a href="https://github.com/ruby/ruby/blob/12c7321d758c736d42dbbd36c74628f7a243851e/lib/monitor.rb#L230" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fruby%2Fruby%2Fblob%2F12c7321d758c736d42dbbd36c74628f7a243851e%2Flib%2Fmonitor.rb%23L230\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-IeiWtxIVbfnZnirJcmF3ykQsZw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fruby%2Fruby%2Fblob%2F12c7321d758c736d42dbbd36c74628f7a243851e%2Flib%2Fmonitor.rb%23L230\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-IeiWtxIVbfnZnirJcmF3ykQsZw&#39;;return true;">https://github.com/ruby/ruby/blob/12c7321d758c736d42dbbd36c74628f7a243851e/lib/monitor.rb#L230

I'm attaching a few screenshots from NewRelic.

My question is - what is the reason ActiveRecord is taking this lock? Is there anything I can do to get a better response from the queries.

The database itself is pretty small - thousands of records.

thanks,
thushara


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="gsgz-G85CAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-core/b5e55010-a295-4d3d-8402-0582a5f5b6f3%40googlegroups.com.
<Screen Shot 2020-02-25 at 9.42.14 AM.png>
<Screen Shot 2020-02-25 at 9.43.14 AM.png>
<Screen Shot 2020-02-25 at 9.46.06 AM.png>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/f3d47e35-cc5d-4f20-85fa-117cd9007eb9%40googlegroups.com.