Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Web Portal: Optimize speed of npm start #1021

Merged
merged 5 commits into from
Aug 3, 2018

Conversation

Gerhut
Copy link
Member

@Gerhut Gerhut commented Jul 31, 2018

  1. Move npm run build run in image build stage, decouple with env.
  2. Inject env to window.ENV in env.js, refernced by all pages.
  3. Rename webportal.config.json to js, which exports window.ENV.

Closes #936

@Gerhut Gerhut requested review from hwuu and abuccts July 31, 2018 07:29
@coveralls
Copy link

coveralls commented Jul 31, 2018

Coverage Status

Coverage decreased (-11.7%) to 51.84% when pulling dea6d32 on qixcheng/web-portal/optimize-boot-speed into 2aa9b06 on master.

@Gerhut
Copy link
Member Author

Gerhut commented Aug 1, 2018

Docs will be updated after #1000 merged

Copy link

@sterowang sterowang left a comment

Choose a reason for hiding this comment

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

:shipit:

"test": "npm run lint",
"webpack": "webpack --config webpack.config.js --progress --profile",
"clean": "rimraf dist",
"prebuild": "npm run clean && node config/preprocess.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

When are prebuild and prestart called?

Copy link
Member Author

@Gerhut Gerhut Aug 1, 2018

Choose a reason for hiding this comment

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

@hwuu They run automatically just before build & start

https://docs.npmjs.com/misc/scripts

@@ -114,6 +114,6 @@
<div class="control-sidebar-bg"></div>

</div>

<script src="scripts/env.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you add this to this .ejs file? I'm wondering whether 'require' the .js file in job-view.component.js is sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

@hwuu layout.component.ejs is the base template of all html pages, it makes all page scripts can access window.ENV by require('webportal.config.js')

@@ -0,0 +1,10 @@
/* eslint-disable */
window.ENV = {
Copy link
Contributor

@hwuu hwuu Aug 1, 2018

Choose a reason for hiding this comment

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

I'm curious about how your method works. I guess this env.js is a template, and it will be dynamically instantiated by envsub inside the container before the service starts (the 'prestart' command of npm). Am I right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@hwuu You are right, this makes the environment variables injected to window.ENV in the runtime, not related to webpack build.

@@ -19,7 +19,7 @@

const hardwareDetailComponent = require('./hardware-detail.component.ejs');
const breadcrumbComponent = require('../../job/breadcrumb/breadcrumb.component.ejs');
const webportalConfig = require('../../config/webportal.config.json');
const webportalConfig = require('../../config/webportal.config.js');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a common practice that we'd better 'require' a .js file other than a .json file?

Copy link
Member Author

Choose a reason for hiding this comment

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

@hwuu In fact require('webportal.config') is better, it will make webpack to choose the most suitable extension, even .ts if exists and related plugin is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for your clarification. All clear. Approved.

@Gerhut
Copy link
Member Author

Gerhut commented Aug 2, 2018

Benchmarks:

Optimization \ Stage Build Run
without 56.738s 30.9s
with 1:32.97s 0.3s

Build:

  • time docker build --tag webportal .
  • Record total seconds

Run:

  • docker run --detach --name container_name image_tag
  • docker logs --timestamp container_name
  • Record timestamp of first line & listening line, calculate difference

Gerhut added 2 commits August 2, 2018 16:50
1. Move `npm run build` run in image build stage, decouple with env.
2. Inject env to `window.ENV` in `env.js`, refernced by all pages.
3. Rename `webportal.config.json` to js, which exports `window.ENV`.
@Gerhut Gerhut force-pushed the qixcheng/web-portal/optimize-boot-speed branch 2 times, most recently from 5016861 to 2bee67c Compare August 2, 2018 10:03
@Gerhut Gerhut force-pushed the qixcheng/web-portal/optimize-boot-speed branch from 2bee67c to 90b380e Compare August 2, 2018 10:18
@@ -74,7 +74,7 @@
"prebuild": "npm run clean && node config/preprocess.js",
"build": "webpack --config webpack.config.js --progress --profile",
"build:dev": "npm run build -- --debug --devtool eval-cheap-module-source-map --output-pathinfo --watch",
"prestart": "envsub --env-file .env --system src/app/env.js dist/scripts/env.js",
"prestart": "envsub --env-file .env --system src/app/env.js dist/scripts/env.js && ping -c 1 -W 1 172.17.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain a little?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a workaround to pass the cluster deploy test in Jenkins, not related to this optimization. I will revert it and raise a new PR to discuss it.

@Gerhut Gerhut merged commit 2c66734 into master Aug 3, 2018
@Gerhut Gerhut deleted the qixcheng/web-portal/optimize-boot-speed branch August 3, 2018 02:09
Gerhut added a commit that referenced this pull request Aug 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants