Build and Deploy React on a Scrawny Machine
Integral Consulting Company
High impact software PODs, building elegant, intuitive and lasting solutions
This is a technical post which is really an "interesting share" (a ritual we follow during our daily morning meetings at Integral: giving everyone a chance to share something interesting with the rest of the team) and a surprising find which we are curious about.
Recently, we have been having issues with deploying some of our React apps because React-Build has become a terrible Memory and CPU hog on our machines. Our CICD methodology is simple (build/deploy on same machine via Docker Compose).?So, we did talk about separating Build and Prod machines so that we could spin up beefier Build Machines and then deploy the artifacts to the scrawnier Prod machines we have. However, that takes time and effort...
But the problem was getting pretty annoying: about a month ago, a deploy process crashed the Prod machine and we had to reach out to the sysadmins (at a client) to restart the VM. The build process had eaten up all last bits of memory and CPU that was available, rendering the machine a useless brick (remotely). So the proverbial on-off button had to be pressed on site (Hypervisor) and my head down in shame for having caused a catastrophic crash!
That's when, I vowed never to do deploy as a normal priority process.?So even if Build becomes too much for the server, other key processes for us "remoters", such as tty and ssh-related processes, will not be choked by the excessive load imposed by React Build.
So, we have been using a simple Unix trick:
领英推荐
#?As SUDO
nice -n 10 docker-compose build
Then once the application is built, a simple:
docker-compose up -d
Well to my surprise, and as a side effect, which I do not know why, “nice”ing the Build process has actually sped up the actual build process and its resource consumption, too!?We have not done a rigorous and scientific measurement to see the change in build-time, but in the last 2-3 releases, which all included changes in the React Application, we just noticed being pleasantly surprised by Build finishing much earlier than usual, and of course without crashing the server.
Very interested in collaborating and chatting with people who have experienced this or can educate us on how potentially "nice"ing React-Build can improve its performance. As counter intuitive as that might sound!
Sounds like you're hitting a resource limit that's causing some "thrashing" with respect to CPU time. It could be that the nice'd process doesn't get interrupted as much and there is less contention on ram usage, I/O or context switch overhead.