R
Railway13mo ago
smaig

Ktor server uses a lot of memory

My ktor server uses a lot of memory , I do not know how it should be or I have problems with the code . Did the ktor server fail how much memory does it consume for you ?
No description
53 Replies
Percy
Percy13mo ago
Project ID: N/A
Fragly
Fragly13mo ago
That is a lot of memory 👀 What does your ktor server do?
Medim
Medim13mo ago
Your KTOR is using what engine? JVM?
Brody
Brody13mo ago
there's also the chance ktor is starting far too many worker processes try to set fixed group sizes like in this example https://ktor.io/docs/configuration-code.html#embedded-engine
smaig
smaig13mo ago
Yes It 's a small messenger , but I 'm developing it , there aren 't even any users there yet Is it important? , there 's just another Kotlin SDK there , but I can 't build a project through it
Medim
Medim13mo ago
Maybe u can manipulate jvm arguments to lower the max and minimum ram it uses, just my thought tho, since its a consistent usage
smaig
smaig13mo ago
My server is simple, folders in which there are files in which various routes are recorded, receive here, send here and everything uses the database database.
smaig
smaig13mo ago
No description
smaig
smaig13mo ago
No description
smaig
smaig13mo ago
There are many different routes in the program , and I call them in the main function
Brody
Brody13mo ago
^
smaig
smaig13mo ago
This did not help the server for some reason still uses a large amount of memory @Brody
No description
No description
Adam
Adam13mo ago
look into lowering the max amount of ram it can use
Adam
Adam13mo ago
Stack Overflow
What are the -Xms and -Xmx parameters when starting JVM?
Please explain the use of the Xms and Xmx parameters in JVMs. What are the default values for them?
Adam
Adam13mo ago
I believe 2gb is the default, so your usage makes sense
smaig
smaig13mo ago
I read about it and it interested me. I just don’t know where to change it, where to write it @Adam
Adam
Adam13mo ago
It’ll be in your start command or as an env variable
Medim
Medim13mo ago
Do you use a custom dockerfile or do you use Nixpacks? If its a Docker file, its set in the java command, example: java -Xms16M -Xmx2G -jar yourjar.jar remember: -Xms = Initial memory -Xmx = max memory keep us updated btw, wanna see the resolution to this
smaig
smaig13mo ago
ok
smaig
smaig13mo ago
I tried a lot and it doesn't work .
No description
Medim
Medim13mo ago
... I don't think thats where ur supposed to put it. Im not at home rn I will search about it when i'm free salute setting it as an .env var JAVA_OPTS="-Xmx2G -Xms16M"
smaig
smaig13mo ago
it doesn't work
smaig
smaig13mo ago
I don 't understand why there is 8 GB of memory in my pocket , and I have to pay for them separately
No description
Brody
Brody13mo ago
that's what your plan allows you to use up to, you pay for the resources you use if your service uses 2gb of ram, that's what you will be charged for if you aren't happy with the resources your app uses you can always look into using a more memory efficient language
Medim
Medim13mo ago
Also, there's a Ktor template on railway https://railway.app/template/zB6nSu u can base urself on that one
Medim
Medim13mo ago
GitHub
ktor-starter/gradlew at master · richardamare/ktor-starter
Contribute to richardamare/ktor-starter development by creating an account on GitHub.
Medim
Medim13mo ago
U can fork it and edit.
smaig
smaig13mo ago
No description
smaig
smaig13mo ago
like this is it
Medim
Medim13mo ago
And you can also try this but as DEFAULT_JVM_OPTS instead of JAVA_OPTS Idk if that two lines its all it takes to set those params, u better take a look at that entire repo.
smaig
smaig13mo ago
I am fully studying the source code of this repository 1 it didn't help. 2 I looked at his code, the project is too small, there is only one route and it doesn’t even take anything from the database
smaig
smaig13mo ago
No description
Medim
Medim13mo ago
I'm out of ideas cryingman
Brody
Brody13mo ago
...i mean
smaig
smaig13mo ago
I think I found it
smaig
smaig13mo ago
No description
smaig
smaig13mo ago
new commit yes its work
smaig
smaig13mo ago
No description
smaig
smaig13mo ago
I'll install the server at night and tell you tomorrow, but I realized that the main documentation for setting up the server is incorrect @Brody @Medim @Adam @Fragly
Brody
Brody13mo ago
adam did tell you to do that, we thought you had already tried that
Medim
Medim13mo ago
cool!
Solution
smaig
smaig13mo ago
No description
No description
Brody
Brody13mo ago
exactly what adam told you to do 😐
smaig
smaig13mo ago
I'm very ashamed that I didn't understand you
Brody
Brody13mo ago
to your credit, nixpacks should probably set saine min/max memory values for this
smaig
smaig13mo ago
I thought there was no need to change anything on the railway
Brody
Brody13mo ago
unfortunaly it seems like this has been overlooked a tad
smaig
smaig13mo ago
That's probably why it eats up a lot of memory
Brody
Brody13mo ago
indeed @jr possible room for improvement on the java provider?
smaig
smaig13mo ago
It is necessary to change the documentation for subsequent users, otherwise this is a significant flaw.
Brody
Brody13mo ago
lets see what jr says
jr
jr13mo ago
I don't think Nixpacks should decide how much memory the application can use. Some apps may want to use as much as possible. However, I think providing some config option either through an env var or UI would be a good idea. At the very least have docs
Adam
Adam13mo ago
I agree. seems like the default for your config is 2GB which seems reasonable. I wouldn’t want my app to be handicapped at 512mb by default OR use the full 8GB. 2GB seems like a happy medium
Want results from more Discord servers?
Add your server