Skip to content
rust deploy uses 10x more ram than local dev

3 years ago

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 anymore

Closed

179 Replies

3 years ago

dockerfile or nixpacks?


3 years ago

nixpacks


3 years ago

// nixpacks.toml
providers = ['rust']

[phases.build]
cmds = ['echo building xylex image', 'cargo build --package xylex']

[phases.test]
cmds = ["cargo test --package xylex"]
dependsOn = ["build"]

[start]
cmd = 'cargo run --package xylex'

[variables]
NIXPACKS_INSTALL_CACHE_DIRS = './nixpacks_cache'
NIXPACKS_BUILD_CACHE_DIRS = './nixpacks_cache'

3 years ago

you should not do cargo run as the start command, you should be building a release and then running the resulting binary


3 years ago

i had a cargo run --release


3 years ago

but i just changed it a few min ago


3 years ago

let's see your new nixpacks.toml file please


3 years ago

additionally, @salvage your input here would be greatly appreciated


3 years ago

// nixpacks.toml
providers = ['rust']

[phases.build]
cmds = ['echo building xylex image', 'cargo build --release --package xylex']

[phases.test]
cmds = ["cargo test --package xylex"]
dependsOn = ["build"]

[start]
cmd = './target/release/xylex'

[variables]
NIXPACKS_INSTALL_CACHE_DIRS = './nixpacks_cache'
NIXPACKS_BUILD_CACHE_DIRS = './nixpacks_cache'

3 years ago

yeah that looks appropriate now


3 years ago

yeah well i used to do it like this in the start but had tremendous amount of issues as you might remember


3 years ago

it would just brick and never deploy unless done via the cli


3 years ago

I do remember, did you also have those variables set? I don't see any purpose to them and can see them causing issues


3 years ago

yes


3 years ago

no


3 years ago

i hadn't set them yet


3 years ago

this is just me trying to get it working in a normal way


3 years ago

for good measure, remove them please


3 years ago

the nixpacks_cache ?


3 years ago

and then let me know if you run into further issues


3 years ago

yes, both those variables you have there


3 years ago

okay, gotcha 2 min


3 years ago

the target could be up to 20gb in some weird c folder hence i deferred it to the cache folder


3 years ago

I'm assuming the default cache stuff nixpacks does is sufficient


3 years ago

compiling rn


3 years ago

same issue as before


3 years ago

on railway and on nixpacks locally



3 years ago

just freezes there?


3 years ago

yes


3 years ago

god


3 years ago

i love railway


3 years ago

the rust provider in nixpacks honestly is shit


3 years ago

but rust


3 years ago

has been very painful to work with on railway


3 years ago

yeah i've moved to cargo-chef


3 years ago

in a dockerfile


3 years ago

i was reading about that yesterday


3 years ago

haha milo beat me to it


3 years ago

much better then nixpacks


3 years ago

agree with Milo here


3 years ago

also this issue looks unrelated to nixpacks


3 years ago

right okay, so you advise me to do the same


3 years ago

im not sure, it stalls local and on railway


3 years ago

nixpacks or


3 years ago

yes


3 years ago

okay nevermind


3 years ago

this is a nixpacks issue 😂



3 years ago

im not sure why it is making it stall that bad though


3 years ago

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


3 years ago

we still chilling here


3 years ago

from yours truly


3 years ago

yeah it was the exact same issue months ago


3 years ago

somehow the cli fixed it


3 years ago

just use cargo-chef, see if that helps


3 years ago

omw


3 years ago

yep cargo chef in a dockerfile for sure


3 years ago

ping me if this happens again (or get brody to lol)



3 years ago

yeah as funnily enough we went to rust cus of low resource usage


3 years ago

whahaha


3 years ago

no you dont need to install it


3 years ago


3 years ago

you just make the recipe.json ?


3 years ago

i am


3 years ago

you do all that in the dockerfile



3 years ago

ah i see


3 years ago

jsut look at the example



3 years ago

should be able to copy most of that


3 years ago

yup



3 years ago

delete ur nixpacks.toml


3 years ago

make sure the Dockerfile is named Dockerfile


3 years ago

yes wait im showing u something




3 years ago

thats just nixpacks doing extra stuff


3 years ago

dont worry about that


3 years ago

please delete ur nixpacks,toml


3 years ago

you somehow needed up with two rust providers


3 years ago

but yeah, Dockerfile time


3 years ago

well i think it's a bug in NixPacks when cargo workspaces are enabled


3 years ago

as xylex_wss is not the main bin


3 years ago

it starts building a random workspace and the core bin


3 years ago

nixpacks and rust dont mix unfortunately


3 years ago

going to docker now ig


3 years ago

yup


3 years ago

fucking hate docker time consuming


3 years ago

not really


3 years ago

this will be easy


3 years ago

yeah you won't need any kind of complex Dockerfile


3 years ago

okay so i changed these from app to xylex

1224473010250186752


3 years ago

anything besides that ?


3 years ago

my cargo is called xylex


3 years ago

what is the binary u wanna


3 years ago

okay


3 years ago

cool


3 years ago

should be good


3 years ago

railway autodetects this yes


3 years ago

yes



3 years ago

let us know how it goes


3 years ago

and please cancel those old deployments


3 years ago

whahah yes i will



3 years ago

i am guessing one of these should've been app still


3 years ago

I assume that means you need to install openssl


3 years ago

bros too experienced


3 years ago

RUN apt update -y && apt install openssl libssl-dev -y


3 years ago

put that in the line before the ENTRYPOINT instruction


3 years ago

perfect


3 years ago

man idk where milo came from but they needa give him a raise


3 years ago

bro's got shortcuts to paste solutions


3 years ago

Milo is the rust professional around here


3 years ago

what a king


3 years ago

fr


3 years ago

just from my personal rust app dockerfile haha


3 years ago

are you in the railway dev team milo


3 years ago

he's not, just a community mod


3 years ago

i see, so it is personal projects/companies that u used rust in


3 years ago

yeah, some enterprise things as well


3 years ago

rust is really good and scalable in my experience


3 years ago

yes we switched in january it is amazing


3 years ago

haha



3 years ago

i am unsure if the ssl install was the right call


3 years ago

certificate verify failed"


3 years ago


3 years ago

what dependencies are u using


3 years ago

might need ca-certificates too? just a guess


3 years ago

shouldn't matter it deploys fine on ubuntu server


3 years ago

can you send ur cargo.toml


3 years ago

yes


3 years ago

I mean this is not the same at all though


3 years ago

are you calling reqwest directly


3 years ago

alright brace for impact guys


3 years ago

// cargo.toml 
[package]
name = "xylex"
version = "0.1.0"
edition = "2021"


[dependencies]
polars = {version = "0.35.0", features = ["lazy", "rolling_window"] }
reqwest = { version = "0.11.23", features = ["json", "blocking"] }
tokio = { version = "1.35.1", features = ["full", "macros", "rt-multi-thread"] }
chrono = { version = "0.4", features = ["serde"] }
serde  = { version = "1.0.196", features = ["derive"] }
supabase_rs = "0.2.2"
thiserror = "1"
rocket = "0.5.0"
serde_json = "1.0.111"
dotenv = "0.15.0"
mail-send = "0.4.6"
mail-builder = "0.3.1"
rsi = "0.1.2"
csv = "1.1"
arrow = "*"
serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "collector"] }
clokwerk = "0.4.0"
image = "0.24.8"
rusttype = "0.9.3"
rand = "0.8.5"
qrcode = "0.13"
async-trait = "0.1.77"
futures = "0.3.3"
imageproc = "0.23.0"
tokio-tungstenite = { version = "0.21.0", features = ["native-tls"] }
serde_yaml = "0.9.31"
lazy_static = "1.4.0"
trading_sessions = "0.1.2"
md-5 = "0.10.6"
hex-literal = "0.4.1"
fibonacci_retracement = "0.1.0"
futures-util = "0.3.30"
futures-channel = "0.3.30"
url = "2.5.0"
sha256 = "1.5.0"
strum = "0.26"
strum_macros = "0.26"
sled = "0.34.7"

xylex_spread_tracker = { path = "./xylex_spread_tracker" }
xylex_card_generator = { path = "./xylex_card_generator" }
xylex_hash_router = { path = "./xylex_hash_router" }
xylex_scheduler = { path = "./xylex_scheduler" }
xylex_discord = { path = "./xylex_discord"}

[dev-dependencies]
anyhow = "1"

[profile.dev]
opt-level = 0
incremental = true


[profile.release]
opt-level = 3

[workspace]
members = [
    "xylex_wss",
    "xylex_card_generator",
    "xylex_spread_tracker",
    "xylex_scheduler",
    "xylex_hash_router",
    "xylex_discord"
]
[package]
name = "xylex_card_generator"
version = "0.1.0"
edition = "2021"

[dependencies]
image = "0.25.0"
imageproc = "0.24.0"
reqwest = "0.12.2"
rusttype = "0.9.3"
serde = "1.0.197"
serde_json = "1.0.114"
serde_yaml = "0.9.34"
[package]
name = "xylex_discord"
version = "0.1.0"
edition = "2021"

[dependencies]
serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "collector"] }
tokio = { version = "1.35.1", features = ["full", "macros", "rt-multi-thread"] }
chrono = { version = "0.4", features = ["serde"] }
serde  = { version = "1.0.196", features = ["derive"] }
thiserror = "1"
serde_json = "1.0.111"
dotenv = "0.15.0"
serde_yaml = "0.9.31"
reqwest = "0.12.2"

[dev-dependencies]
anyhow = "1"

[profile.dev]
opt-level = 0
incremental = true

[profile.release]
opt-level = 3
[package]
name = "xylex_hash_router"
version = "0.1.0"
edition = "2021"

[dependencies]
dotenv = "0.15.0"
serde_json = "1.0.115"
supabase_rs = "0.2.2"
[package]
name = "xylex_spread_tracker"
version = "0.1.0"
edition = "2021"

[dependencies]
regex = "1.10.4"
reqwest = "0.12.2"
serde = "1.0.197"
serde_derive = "1.0.197"
serde_json = "1.0.115"
serde_yaml = "0.9.34"
supabase_rs = "0.2.2"
tokio = "1.36.0"
[package]
name = "xylex_wss"
version = "0.1.0"
edition = "2021"

[dependencies]
amqprs = "1.5.3"
serde = "1.0.197"
serde_json = "1.0.114"
serde_yaml = "0.9.34"
tokio =  "1.36.0"

3 years ago

you can attach files lmao


3 years ago

oh


3 years ago

well this works too


3 years ago

add rustls-tls as a feature of reqwest


3 years ago

also, half these depenendices are obsolete and can be replaced by something better, not needed at all, or stdlib


3 years ago

i mean bro


3 years ago

im sure


3 years ago

but i'm not sure if refactoring 155k lines of rust is something i wanna do tonight


3 years ago

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


3 years ago

anyways


3 years ago

do this please


3 years ago

yes its deploying


3 years ago

okay cool


3 years ago

damn Milo knows his stuff


3 years ago

yeah but what's the difference between dotenv and dotenvy


3 years ago

dotenvy is maintained and isn't.. bad



3 years ago

i see ill make a linear ticket ig


3 years ago

same api, literally just changing crate name


3 years ago

anyways!


3 years ago

same issue lmfao


3 years ago

screenshot of error



3 years ago

"certificate verify failed", file


3 years ago

well then i dont know why


3 years ago

show me the line of code


3 years ago

that is causing this erorr


3 years ago

every single one that does an api request


3 years ago

maybe?


3 years ago

show me please


3 years ago

pub async fn discord_logs(
    log_message: &str
) -> Result<(), Box> {
    let client: Client = Client::new();
    let webhook_url: String = env::var("DISCORD_WEBHOOK_URL").unwrap();
    let current_time: String = Utc::now().to_string();

    client.post(&webhook_url)
        .body(json!({
            "content": format!(
                "**xylex-daemon @ {} | **{}",
                current_time, log_message
            )

        }).to_string())
        .header(
            "Content-Type",
             "application/json"
        )
        .send()
        .await?;

    Ok(())
}

3 years ago

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


3 years ago

well thats norrmal about high ram amounts


3 years ago

yeah no clue, you aren't directly telling it to use openssl and the features make it use rustls so im lost


3 years ago

sorry


3 years ago

ig so but only 10-20k lines r being deployed on railway and idle usage used to be 200mb or so


3 years ago

sorry


3 years ago

idk


3 years ago

thanks for the help though guys, i appreciate your time have a good night


Welcome!

Sign in to your Railway account to join the conversation.

Loading...