Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular universal consumes a lot of cpu

right now I am putting in place a server side rendering for my website made with angular 5.

I managed to put angular universal in place but I encounter a problem and I absolutely can not solve it or work around it.

I noticed that when loading the first page when we arrive on the site, it consumes a lot of cpu but during navigation once the first page loaded it consumes nothing, after doing several tests, I can even crash the website.

I thought to cache the pages but I do not know how to do it because I need them to be dynamic according to the requests on my API ..

So I ask you this question, is there a way to reduce the consumption of cpu or a way around this problem? thank you !

like image 682
Martinoss Avatar asked Nov 07 '22 06:11

Martinoss


1 Answers

You should only need similar amount of CPU time server-side as compared to using Angular client-side. Once your page is loaded, there isn't much to compute during navigation -- this is the reason for SPA.

The server-side rendered app is transitioned to client's side when it is bootstrap. Unless you are sending requests to your server, there should not be any CPU activities in your server.

The reason for the 'high' consumption of CPU in your server may be due to bugs that happens when your Angular app is bootstrapped, rendered server-side. Test your server side rendered app without JavaScript using a local server and check the server logs/browser console logs for errors.

If you can't find any error, you might want to check the app for memory leaks. When the memory limit is reached in your server, CPU usage will be extremely high due to page trashing.

like image 54
Joshua Chan Avatar answered Nov 14 '22 23:11

Joshua Chan