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

request module takes too long to require #1340

Closed
rickwargo opened this issue Mar 22, 2017 · 1 comment
Closed

request module takes too long to require #1340

rickwargo opened this issue Mar 22, 2017 · 1 comment

Comments

@rickwargo
Copy link

Trying to simply load the requests module (version 2.67) takes too long for an azure function. It can take anywhere between 30 - 45 seconds to return. Running a second time without a code change occurs as it should. After a code change, it takes a long while to load, but not as long as the first time, maybe 3 - 4 seconds.

Repro steps

  1. Step A - Create a new Webhook Javascript function
  2. Step B - set up package.json and npm install
  3. Step C - use the following code for index.js:
module.exports = function (context, data) {
    // context.log('now with code change.');                // comment this out for runs 3, 4
    // context.log('now with another code change.');  // comment this out for runs 5, 6
    // context.log("about to require('request')");          // comment this out for runs 7, 8
    var request = require('request');
    context.log("finished require('request')");

    context.done();
}
  1. Step D - run the code eight times (or more). After the first two runs, uncomment the first context.log() to make a code change.. Run it again two times. Uncomment the next context.log() to make another code change. Run it again. And repeat.

Expected behavior

The difference between the two entries for about to require/finished require should be in the millisecond range.

2017-03-22T17:12:45.472 about to require('request')
2017-03-22T17:13:45.472 finished require('request')

Actual behavior

They are not. Here is the output log from my runs:

2017-03-22T17:10:28  Welcome, you are now connected to log-streaming service.
2017-03-22T17:11:28  No new trace in the past 1 min(s).
2017-03-22T17:12:28  No new trace in the past 2 min(s).
2017-03-22T17:12:45.316 Function started (Id=5dc8d244-fde0-4d00-a95a-468aa3ad243a)
2017-03-22T17:12:45.472 about to require('request')
2017-03-22T17:13:22.744 finished require('request')
2017-03-22T17:13:22.744 Function completed (Success, Id=5dc8d244-fde0-4d00-a95a-468aa3ad243a)
2017-03-22T17:13:32.685 Function started (Id=457bfbea-a505-4f88-8655-0b4ebd9cfa65)
2017-03-22T17:13:32.685 about to require('request')
2017-03-22T17:13:32.685 finished require('request')
2017-03-22T17:13:32.685 Function completed (Success, Id=457bfbea-a505-4f88-8655-0b4ebd9cfa65)
2017-03-22T17:13:56.760 Script for function 'RequestBugJS1' changed. Reloading.
2017-03-22T17:14:00.570 Function started (Id=03d91a95-9607-443d-b8b0-9eeb9caf04f2)
2017-03-22T17:14:00.601 now with code change.
2017-03-22T17:14:00.601 about to require('request')
2017-03-22T17:14:04.273 finished require('request')
2017-03-22T17:14:04.273 Function completed (Success, Id=03d91a95-9607-443d-b8b0-9eeb9caf04f2)
2017-03-22T17:14:09.894 Function started (Id=d034dd6e-ffd3-4b83-83c6-3baa95e02897)
2017-03-22T17:14:09.894 now with code change.
2017-03-22T17:14:09.894 about to require('request')
2017-03-22T17:14:09.894 finished require('request')
2017-03-22T17:14:09.894 Function completed (Success, Id=d034dd6e-ffd3-4b83-83c6-3baa95e02897)
2017-03-22T17:14:30.797 Script for function 'RequestBugJS1' changed. Reloading.
2017-03-22T17:14:34.918 Function started (Id=197356c2-f67d-4765-b0e0-63057ab0cb40)
2017-03-22T17:14:34.934 now with code change.
2017-03-22T17:14:34.934 now with another code change.
2017-03-22T17:14:34.934 about to require('request')
2017-03-22T17:14:37.356 finished require('request')
2017-03-22T17:14:37.356 Function completed (Success, Id=197356c2-f67d-4765-b0e0-63057ab0cb40)
2017-03-22T17:14:42.741 Function started (Id=a1ad15bf-2647-4e22-9d37-d2d7aa316ee1)
2017-03-22T17:14:42.741 now with code change.
2017-03-22T17:14:42.741 now with another code change.
2017-03-22T17:14:42.741 about to require('request')
2017-03-22T17:14:42.741 finished require('request')
2017-03-22T17:14:42.741 Function completed (Success, Id=a1ad15bf-2647-4e22-9d37-d2d7aa316ee1)

Known workarounds

None

Related information

Provide any related information

  • Programming language used: Javascript
@mamaso
Copy link
Contributor

mamaso commented Mar 23, 2017

Closing as a duplicate of #298.

This is a limitation of cold starts and our file system in consumption plan which we are trying to improve.

One answer we have at the moment is to pack node_modules, which greatly improves require times for most modules - https://github.com/christopheranderson/azure-functions-pack

@mamaso mamaso closed this as completed Mar 23, 2017
@ghost ghost locked as resolved and limited conversation to collaborators Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants