#memory

39 messages · Page 1 of 1 (latest)

dark orbit
#

Hi guys. im new to nestjs,
and my app running via pm2 nginx
is consuming 100% CPU, any help? 😦

#

P.S. this is just a single post req. endpoint

stoic cobalt
#

100% of how much?

outer trellis
#

do you have any recursive function or .map/.reduce/.foreach?

dark orbit
#

this is for registering of users,
with username/email validation if exist or not,
and saves to mongodb , that is all

dark orbit
stoic cobalt
#

Average sized Nest apps consume around 300 MB, so if your total is half a gig, I'd say you're just below the limit

dark orbit
#

its 1gb

stoic cobalt
#

Also make sure you're starting just the built app with node dist/main. The npm layer adds some overhead.

dark orbit
#

do you think dockerizing it would help?

stoic cobalt
#

1 GB should be plenty for a mid sized app. I don't know how much pm2 and nginx consume together

outer trellis
#

im pretty sure that is some problem directly with the application and dockerize couldnt do much

dark orbit
#

what about rate limiting

#

i really appreciate the quick repsonse, this community is awesome

stoic cobalt
dark orbit
#

i see

outer trellis
#

other point, how many times did you called the endpoint?

stoic cobalt
dark orbit
#

im stress testing it

#

trying to post with the same username as a sample

high shore
#

Check with pm2 logs

#

If you are having any loop

dark orbit
#

it validates normally, however on success , it freezes due to cpu maxed out

#

and the rss logs is just increasing

#

im thinking theres a leak somewhere

#

this is process.memoryUsage btw..

stoic cobalt
#

Well, rate limiting can certainly help (nginx surely has some setting for that. If you already use nginx, you don't need to implement this in node). The other question is whether the stress test is warranted given your expected daily bandwidth and if you can tolerate degraded service when the demand is exceptionally high.

#

Another "solution" is to use asynchronous processing with queues.

#

But all that adds complexity and needs to be warranted given the "business" requirements

dark orbit
#

im thinking of rate limiting

#

but on a second thought, queues sounds fair

#

nah, its just the most basic crap out there, firs ttime deploying nestjs app lol

stoic cobalt
#

Rate limiting is much easier to implement, since you don't need to change the code flow. Asynchronous processing is a complex task, so I wouldn't get into it if you're just starting, unless you have experience with it from other languages, for example. It might be a great excercise though.

outer trellis
#

Yeah, i agree with @stoic cobalt, probably rate limit is a good first approach.

dark orbit
#

thanks a lot man, im not sure what i can give you for this responsive thread

#

but all i can say is you guys are better than chat gpt

#

😄

stoic cobalt