rust deploy uses 10x more ram than local dev
hey guys, i have a rust api that is using 4-8gb of ram suddenly,
now for rust that's unheard of considering it used to chill at 200mb +/-
when running
cargo run --release --package x
locally i get out to a max of 1.5gb ram (this includes compiling)
yet on railway it ticks out to 8gb at peak (this includes compiling)
takes roughly 26 minutes to compile, build, deploy on railway
There's a total of 950 +/- crate dependencies
projectId = 7c6a1d9f-d3d2-4808-96b1-10c8df175503
No deploy that happened in that weird spike, nor am i able to reproduce the low memory usage anymore132 Replies
Project ID:
7c6a1d9f-d3d2-4808-96b1-10c8df175503
dockerfile or nixpacks?
nixpacks
you should not do cargo run as the start command, you should be building a release and then running the resulting binary
i had a cargo run --release
but i just changed it a few min ago
let's see your new nixpacks.toml file please
additionally, @milo / salvage your input here would be greatly appreciated
yeah that looks appropriate now
yeah well i used to do it like this in the start but had tremendous amount of issues as you might remember
it would just brick and never deploy unless done via the cli
I do remember, did you also have those variables set? I don't see any purpose to them and can see them causing issues
yes
no
i hadn't set them yet
this is just me trying to get it working in a normal way
for good measure, remove them please
the nixpacks_cache ?
and then let me know if you run into further issues
yes, both those variables you have there
okay, gotcha 2 min
the target could be up to 20gb in some weird c folder hence i deferred it to the cache folder
I'm assuming the default cache stuff nixpacks does is sufficient
compiling rn
same issue as before
on railway and on nixpacks locally
local
just freezes there?
yes
god
i love railway
the rust provider in nixpacks honestly is shit
but rust
has been very painful to work with on railway
yeah i've moved to cargo-chef
in a dockerfile
i was reading about that yesterday
haha milo beat me to it
much better then nixpacks
agree with Milo here
also this issue looks unrelated to nixpacks
right okay, so you advise me to do the same
im not sure, it stalls local and on railway
nixpacks or
yes
okay nevermind
this is a nixpacks issue 😂
im not sure why it is making it stall that bad though
yes, I'm not a rust dev but have heard great things about cargo chef and when nixpacks is painful (almost always) dockerfiles are the way to go
we still chilling here
from yours truly
yeah it was the exact same issue months ago
somehow the cli fixed it
just use cargo-chef, see if that helps
omw
yep cargo chef in a dockerfile for sure
ping me if this happens again (or get brody to lol)
yeah as funnily enough we went to rust cus of low resource usage
whahaha
no you dont need to install it
please read up how to use it:https://github.com/LukeMathWalker/cargo-chef
GitHub
GitHub - LukeMathWalker/cargo-chef: A cargo-subcommand to speed up ...
A cargo-subcommand to speed up Rust Docker builds using Docker layer caching. - LukeMathWalker/cargo-chef
you just make the recipe.json ?
i am
you do all that in the dockerfile
ah i see
jsut look at the example
this bit
should be able to copy most of that
yup
delete ur nixpacks.toml
make sure the Dockerfile is named Dockerfile
yes wait im showing u something
thats just nixpacks doing extra stuff
dont worry about that
please delete ur nixpacks,toml
you somehow needed up with two rust providers
but yeah, Dockerfile time
well i think it's a bug in NixPacks when cargo workspaces are enabled
as xylex_wss is not the main bin
it starts building a random workspace and the core bin
nixpacks and rust dont mix unfortunately
going to docker now ig
yup
fucking hate docker time consuming
not really
this will be easy
yeah you won't need any kind of complex Dockerfile
okay so i changed these from app to xylex
anything besides that ?
my cargo is called xylex
what is the binary u wanna
okay
cool
should be good
railway autodetects this yes
yes
let us know how it goes
and please cancel those old deployments
whahah yes i will
i am guessing one of these should've been app still
I assume that means you need to install openssl
bros too experienced
RUN apt update -y && apt install openssl libssl-dev -y
put that in the line before the ENTRYPOINT instructionperfect
man idk where milo came from but they needa give him a raise
bro's got shortcuts to paste solutions
Milo is the rust professional around here
what a king
fr
just from my personal rust app dockerfile haha
are you in the railway dev team milo
he's not, just a community mod
i see, so it is personal projects/companies that u used rust in
yeah, some enterprise things as well
rust is really good and scalable in my experience
yes we switched in january it is amazing
haha
i am unsure if the ssl install was the right call
certificate verify failed"
:anguish:
what dependencies are u using
might need ca-certificates too? just a guess
shouldn't matter it deploys fine on ubuntu server
can you send ur cargo.toml
yes
I mean this is not the same at all though
are you calling reqwest directly
alright brace for impact guys
you can attach files lmao
oh
well this works too
add rustls-tls as a feature of
reqwest
also, half these depenendices are obsolete :anguish: and can be replaced by something better, not needed at all, or stdlibi mean bro
im sure
but i'm not sure if refactoring 155k lines of rust is something i wanna do tonight
i mean, you don't need strum-macros if you have strum, lazy-static is just stupid these days, dotenv should use dotenvy and thats just to name a few
anyways
do this please
yes its deploying
okay cool
damn Milo knows his stuff
yeah but what's the difference between dotenv and dotenvy
dotenvy is maintained and isn't.. bad
RUSTSEC-2021-0141: dotenv: dotenv is Unmaintained › RustSec Advisor...
Security advisory database for Rust crates published through https://crates.io
i see ill make a linear ticket ig
same api, literally just changing crate name
anyways!
same issue lmfao
screenshot of error
"certificate verify failed", file
well then i dont know why
show me the line of code
that is causing this erorr
every single one that does an api request
maybe?
show me please
all this shouldn't matter as it works fine on any other deploy it's just railway can't build it unless it's 4-8gb ram
well thats norrmal about high ram amounts
yeah no clue, you aren't directly telling it to use openssl and the features make it use rustls so im lost
sorry
ig so but only 10-20k lines r being deployed on railway and idle usage used to be 200mb or so
sorry
idk
thanks for the help though guys, i appreciate your time have a good night