nuxt: High CPU usage (200%) when running Nuxt dev server in Docker container
Environment
My host system:
- Operating System: Linux (Ubuntu 20.04 LTS)
- Computer: Lenovo Legion 5 (32GB RAM, i5 10th gen)
- Node Version: v18.12.1
- Nuxt Version: 3.7.0
- CLI Version: 3.7.2
- Nitro Version: 2.6.2
- Package Manager: pnpm@8.1.0
- Builder: -
- User Config: devtools, vite
- Runtime Modules: -
- Build Modules: -
Reproduction
https://github.com/martinszeltins/nuxt-docker-cpu
Steps to reproduce the issue:
# Clone the repo
git clone https://github.com/martinszeltins/nuxt-docker-cpu.git
cd nuxt-docker-cpu
# Run the Docker container
docker-compose up -d
docker-compose logs --follow
# Wait for it to install dependencies and build the
# app (you will see it in the logs, it happens automatically)
# Run the Nuxt dev server
docker exec -it nuxt-docker-client pnpm run dev
Describe the bug
I have tried to keep the reproduction as minimal as possible, it is a fresh Nuxt app put inside a Docker container, nothing more. The issue that I am seeing is that the CPU usage is very high, fluctuating between 100% and 200%. This makes my computer’s fans spin up and it stays this way even when I am not doing anything. The app just stays open and does nothing and the CPU spins like crazy. To me it seems like the CPU should be close to 0% because nothing should be happening. When running a plain Vue / Vite app dev server in a container I did not notice this issue, only with Nuxt.
This happens only when running the dev sever in Docker, not locally. Maybe Nuxt has a problem with Linux or being run from a Docker container, I’m not sure. What is Nuxt dev server doing all the time in the background that the CPU usage is so high? 🤔 As soon as I stop the dev server, the CPU usage goes back to normal.
I did not know how to investigate this issue further because I don’t know the inner workings of Nuxt but it seems like some kind of resource leak is happening here. 🤷🏻♂️
Here is my CPU usage BEFORE I start the dev server:
And here is my CPU usage AFTER I have started the dev server:
Additional context
No response
Logs
No response
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 15 (11 by maintainers)
Commits related to this issue
- fix(schema): ignore pnpm store directory resolves https://github.com/nuxt/nuxt/issues/22910 — committed to nuxt/nuxt by danielroe 9 months ago
- fix(schema): ignore pnpm store directory resolves https://github.com/nuxt/nuxt/issues/22910 — committed to NozomuIkuta/nuxt by danielroe 9 months ago
I think not as we only watch at depth: 0 in the cli.
UPDATE: I finally found the issue. When
pnpminstalled the packages in Docker, it created a.pnpm-storedirectory in my project. This caused the watcher to go craaaazy. Once I reconfigured pnpm to place the.pnpm-storedirectory outside of my project, everything became 100% faster and working as normal.pnpm config set store-dir /.pnpm-storeI guess the issue was that by default in Docker pnpm puts the store directory inside the project itself. In this case Nuxt should ignore watching it just like it ignores node-modules.
similar https://github.com/nuxt/cli/issues/118