ghkdqhrbals / portfolio

React기반 포트폴리오 페이지 프로젝트입니다.
0 stars 0 forks source link

npm installation is too slow #5

Open ghkdqhrbals opened 2 years ago

ghkdqhrbals commented 2 years ago

In AWS EC2 instance, i want to set up docker infrastructure.

So i run docker compose up to run npm install & build & run for my portfolio web.

But, in npm install stage, it is TOO SLOW.

Dockerfile.prod

FROM node:18-alpine3.16 AS builder WORKDIR /react-portfolio-website

ENV PATH="./node_modules/.bin:$PATH" COPY package.json ./ RUN npm install COPY . . RUN npm run build

FROM nginx COPY --from=builder /react-portfolio-website/build /usr/share/nginx/html

docker-compose.yml

version: "3.8"

services: app: build: context: . dockerfile: Dockerfile.prod volumes:

  • .:/react-portfolio-website ports:
  • "80:80" command: npm start

image

How can i reduce npm install time?

ghkdqhrbals commented 2 years ago

Yarn vs. NPM: How to Choose It's essential to consider the advantages and disadvantages of both NPM and Yarn when deciding which one to use.

Yarn

Advantages

Supports parallel installation and Zero installs, both of which dramatically increase performance. Newer versions of Yarn offer a more secure form of version locking. Active user community.

Disadvantages

Yarn doesn't work with Node.js versions older than version 5. Yarn has shown problems when trying to install native modules.

NPM

Advantages

Easy to use, especially for developers used to the workflow of older versions. Local package installation is optimized to save hard drive space. The simple UI helps reduce development time.

Disadvantages

The online NPM registry can become unreliable in case of performance issues. This also means that NPM requires network access to install packages from the registry. Despite a series of improvements across different versions, there are still security vulnerabilities when installing packages. Command output can be difficult to read.

ghkdqhrbals commented 2 years ago

Check same issue https://github.com/moby/moby/issues/27824#issuecomment-290678262

ghkdqhrbals commented 2 years ago

Case Solved!

Since YARN support parallel package installation(with yarn.lock file), it is faster than NPM over 20 times. Thus Docker container of my Web service in EC2 instance can be updated faster(in 5 min).

Conclusion with this summary Yarn vs NPM (2021.09.04)

NPM install packages sequentially, Yarn installs in-parallel. Here is the speed and performance between NPM, YARN.