Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline require causes performance issues #2506

Closed
wants to merge 1 commit into from

Conversation

trenton05
Copy link

Description

Please provide a brief description of the changes introduced in this pull request.
What problem does it solve? What is the context of this change?

The combination of code-level-metrics require('@contrast/fn-inspect') with @newrelic/ritm being hooked into requires causes a cascading load issue for nodejs.

How to Test

Please describe how you have tested these changes. Have you run the code against an example application?
What steps did you take to ensure that the changes are working correctly?

For reference, our express server with newrelic was taking 10 seconds to handle 500 requests. After this change, the same 500 requests takes about half a second. Should be able to be tested with a similar configuration.

Related Issues

Please include any related issues or pull requests in this section, using the format Closes #<issue number> or Fixes #<issue number> if applicable.

Creating this to capture the issue and fix for the newrelic team, we have patched it locally so that we do not run across this issue anymore.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -8,6 +8,7 @@ const logger = require('../logger').child({ component: 'code-level-metrics' })
const { isValidLength } = require('./byte-limit')
const symbols = require('../symbols')
const clmUtils = module.exports
const { funcInfo } = require('@contrast/fn-inspect')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was required in a try/catch because this dep is optional. If hoisting the require to top solves the issue, we need to wrap this in a try/catch at the very least. but i'd like to see a repro case so i can dig into the root cause

@bizob2828
Copy link
Member

@trenton05 we require conventional commits, can you please fix up your PR title at the very least because that's what we'll use on merge

@bizob2828
Copy link
Member

@trenton05 just following up. can you please provide a repro case so we can dig into the root cause and validate that this fix will be enough?

@bizob2828
Copy link
Member

@trenton05 I'm going to close this. there has been no response to my questions. If you can provide a reproduction case, please reopen this PR

@bizob2828 bizob2828 closed this Sep 17, 2024
@trenton05
Copy link
Author

Sorry I don't have the time to setup a test. A simple express server handling requests can easily be benchmarked. I made this PR to let your team know it was a serious issue on our end and this resolved it for us.

@bizob2828
Copy link
Member

Sorry I don't have the time to setup a test. A simple express server handling requests can easily be benchmarked. I made this PR to let your team know it was a serious issue on our end and this resolved it for us.

Ok i'll see if I can reproduce and follow up

@bizob2828
Copy link
Member

@trenton05 I used a simple express server and ran 1000 requests with and without this change and see no difference in response time.

const newrelic = require('newrelic')
const express = require('express')
const app = express()
const { PORT = 3000 } = process.env


app.get('/named-route', (req, res) => {
  res.send('hi')
})

app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))

Something else in play for your case I think, it would be very helpful to provide a reproduction case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done: Issues recently completed
Development

Successfully merging this pull request may close these issues.

3 participants