question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The pg instrumentation includes the waiting time in the client's internal queue when recording query runtime

See original GitHub issue

Got a bit of a jumpscare the other day when we refactored one of our apps in a way that caused us to issue more pg client calls in parallel. The change didn’t affect the number of queries being run or their actual execution times in the database, but newrelic’s graphs reported a severe performance regression:

Screen Shot 2020-05-15 at 12 23 48

Since you cannot multiplex parallel queries into a single postgres connection, the pg client has an internal waiting queue so that each query ends up getting exclusive access: https://github.com/brianc/node-postgres/blob/bf469399b88bcdf86eff096fd0dd05684adc1117/packages/pg/lib/client.js#L557

However, node-newrelic’s instrumentation of the pg module only shims the query method: https://github.com/newrelic/node-newrelic/blob/18de96b2bb37691d6820ad806644753f7cc237fe/lib/instrumentation/pg.js#L54-L60

As far as I can tell, the consequence is that the time the query spends waiting in queryQueue will be counted as part of its runtime. That also explains why the actual request response time reported in the chart above is way lower than the height of the solid colors.

It looks like the instrumentation has to dive one step deeper to account for this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
carlo-808commented, Feb 8, 2021

We were able to reproduce the behavior and a reproduction is here: https://github.com/carlo-808/pg-query-timing-repro

I suspect that we will need to instrument the Query object itself possibly around the submit function. We will get this issue further prioritized.

1reaction
bizob2828commented, Sep 30, 2021

Thanks for reaching out @papandreou. I moved this close to the top of our backlog. We had other priorities come in and this may have got bumped further down the stack than expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Instrumentation
An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
Read more >
Does the wait time include the execution time and the time ...
Wait time implies time waiting for something. Depending on the perspective it could mean waiting on blocked resources or waiting on query to...
Read more >
How can I track the execution of PL/SQL and SQL? - Ask TOM
I want to see it´s run time execution plan but it´s not possible neither when I run SQL> SELECT * FROM v$sql_plan where...
Read more >
Mysql Performance Schema Query Execution Time Example
profiling execution-time profiling and wait. Inner join order to enable users in mysql performance schema query execution time example we discuss later.
Read more >
Tracing Ruby Applications
Setup the Datadog Agent for tracing; Instrument your application ... Distributed tracing; HTTP request queuing; Processing pipeline. Filtering; Processing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found