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

alternatives to npm start #275

Open
evanshortiss opened this issue May 14, 2021 · 3 comments
Open

alternatives to npm start #275

evanshortiss opened this issue May 14, 2021 · 3 comments

Comments

@evanshortiss
Copy link

I've noticed that the resulting s2i image starts the Node.js application using npm start.

This is a good idea since it's common practice and enables a developer to set flags etc, but it does result in two Node.js processes being launched, as seen in this screenshot:

Screenshot 2021-05-14 at 3 21 33 PM

We have the npm process, and then the child node process.

The npm process is mostly idle, but does consume memory and adds overhead on startup.

Screenshot 2021-05-14 at 3 56 57 PM

Is it worth giving consideration to support a new environment variable that defines a shell script to use on startup instead?

@ryanj
Copy link
Contributor

ryanj commented May 14, 2021

This doesn't entirely address the issue, but you should be able to run any script that is defined in your package.json using the NPM_RUN env var.

Last I checked, I think we actually run something like: npm run $NPM_RUN with a default setting of "NPM_RUN=start". I prefer this to DEV_MODE, because restarting everything via nodemon isn't really ideal for inner-loop work.

see https://github.com/sclorg/s2i-nodejs-container/blob/master/14/s2i/bin/run#L20-L26

@evanshortiss
Copy link
Author

evanshortiss commented May 14, 2021

@ryanj I think maybe I need to explain this better. The issue isn't the target script, the issue is overhead of using npm run, since it creates two Node.js processes inside the container. Running node index.js would create just one process.

It's minor, but if someone were to run an image built this way for a serverless/knative application then the 9x increased startup time (see second screenshot) could start to matter.

Edit: Spelling

@mhdawson
Copy link
Member

Fyi - some info/discussion on this topic is provided in the Node.js Reference architecture: https://github.com/nodeshift/nodejs-reference-architecture/blob/main/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application. It would be good to have a way to run without having to use npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants