#Pointless memory increase :/

44 messages · Page 1 of 1 (latest)

peak egret
#

I regularly check the amount of memory I have used for my nodejs project from the RailwayApp Dashboard.
For the last 2 weeks I've been observing strange memory spikes with no problems with my code.
I did this test on my own computer, but I could not observe any increase.
Addendum: I am using Nixpacks in my RailwayApp project. (no alternative options/not active)

verbal wharfBOT
#

Project ID: 58c83e7e-5267-460d-8b9a-4b9f4ca7abe7

peak egret
#

my project id: 58c83e7e-5267-460d-8b9a-4b9f4ca7abe7

#

Pointless memory increase :/

vivid wasp
#

funny thing is that this is one thing I literally pull my brains out all the time. There are many reason for random memory spikes though, like how sometimes the project may not return RAM back to the system

Issue also may be memory leaks from libraries you may be using (this was true for some my python subprocess projects within NodeJS). In this case updating or downgrading the libraries typically solves the problem.

There are some ways to tell NodeJS to use less memory with V8's flags at https://flaviocopes.com/node-runtime-v8-options/

This is still an active issue I am still facing though I hope all these may help you

warm hearth
#

It likely has to do with the monitoring software

#

There’s been bugs before where it shows it as cumulative for some reason

#

It’s just funky software

sand echo
#

Are you talking about Railway's metrics implementation?

#

That issue has been fixed. If there's spikes in usage then it's an issue with your code.

warm hearth
#

Ope

#

Metrics got a fix?

sand echo
#

Like 2 weeks ago yeah

verbal escarp
#

something along the lines of JavaScript native bcrypt hashing, something that is short lived but memory intensive

#

just an example, might spark some ideas

#

calculating strong etags by buffering body into memory, there's so many possibilities

sand echo
#

I was replying to what Alex said above, they called it software which confused me

#

it’s not software

peak egret
sand echo
#

consensus is it’s an issue with your code/a memory leak with a package you’re using

sand echo
#

whatever it is it’s not Railway

peak egret
#

I think I found the source of the problem, I haven't observed an increase for a few hours

app.use(session({ secret: config.cryptrSecretKey, resave: false, saveUninitialized: false, cookie: { expires: 8640000 } }))
app.use((req, res, next) => {
    req.session.ip = req.ip.startsWith('::') ? '0.0.0.0' : req.ip; //THE PROBEM LINE
    const domain = "cihatksm.com";
    if (req.session.ip == "0.0.0.0") return next();
    if (req.headers.host.startsWith("www") || req.headers.host !== domain)
        return res.redirect("http://" + domain + req.url);
    return next()
})```

new code:
```js
app.use((req, res, next) => {
    let ip = req.ip.startsWith('::') ? '0.0.0.0' : req.ip;
    const domain = "cihatksm.com";
    if (ip == "0.0.0.0") return next();
    if (req.headers.host.startsWith("www") || req.headers.host !== domain)
        return res.redirect("http://" + domain + req.url);
    return next()
})
app.use(session({ secret: config.cryptrSecretKey, resave: false, saveUninitialized: false, cookie: { expires: 8640000 } }))```
#

I don't fully understand why this causes memory increase. 😄

#

Thank you for your help

verbal escarp
#

so at least I was in the ballpark with my guesses, glad you got it solved!

warm hearth
#

why are you using let btw

#

also express middleware is confusing yea

verbal escarp
warm hearth
#

let is only for variables that need to be mutated or reassigned

#

const will let you mutate most things but its cringe and not good

#

eslint will scream at you for doing either

verbal escarp
#

linters are lame

#

what the hell are you proposing, not using let or const?

warm hearth
#

Let is for variables that you want to reassign or mutate

#

Const is for variables that never get reassigned or retyped or mutated

#

It’s to stop you from accidentally reassigning a variable which never needs to be

warm hearth
verbal escarp
#

I know I told you that I'm bad at code, but I know that stuff at least believe it or not, but you said const was cringe, hence my confusion