R
Railway14mo 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
Percy14mo ago
Project ID: N/A
Fragly
Fragly14mo ago
That is a lot of memory 👀 What does your ktor server do?
Medim
Medim14mo ago
Your KTOR is using what engine? JVM?
Brody
Brody14mo 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
smaigOP14mo 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
Medim14mo 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
smaigOP14mo 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
smaigOP14mo ago
No description
smaig
smaigOP14mo ago
No description
smaig
smaigOP14mo ago
There are many different routes in the program , and I call them in the main function
Brody
Brody14mo ago
^
smaig
smaigOP14mo ago
This did not help the server for some reason still uses a large amount of memory @Brody
No description
No description
Adam
Adam14mo ago
look into lowering the max amount of ram it can use
Adam
Adam14mo 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
Adam14mo ago
I believe 2gb is the default, so your usage makes sense
smaig
smaigOP14mo ago
I read about it and it interested me. I just don’t know where to change it, where to write it @Adam
Adam
Adam14mo ago
It’ll be in your start command or as an env variable
Medim
Medim14mo 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
smaigOP14mo ago
ok
smaig
smaigOP14mo ago
I tried a lot and it doesn't work .
No description
Medim
Medim14mo 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
smaigOP14mo ago
it doesn't work
smaig
smaigOP14mo 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
Brody14mo 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
Medim14mo ago
Also, there's a Ktor template on railway https://railway.app/template/zB6nSu u can base urself on that one
Medim
Medim14mo ago
GitHub
ktor-starter/gradlew at master · richardamare/ktor-starter
Contribute to richardamare/ktor-starter development by creating an account on GitHub.
Medim
Medim14mo ago
U can fork it and edit.
smaig
smaigOP14mo ago
No description
smaig
smaigOP14mo ago
like this is it
Medim
Medim14mo 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
smaigOP14mo 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
smaigOP14mo ago
No description
Medim
Medim14mo ago
I'm out of ideas cryingman
Brody
Brody14mo ago
...i mean
smaig
smaigOP14mo ago
I think I found it
smaig
smaigOP14mo ago
No description
smaig
smaigOP14mo ago
new commit yes its work
smaig
smaigOP14mo ago
No description
smaig
smaigOP14mo 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
Brody14mo ago
adam did tell you to do that, we thought you had already tried that
Medim
Medim14mo ago
cool!
Solution
smaig
smaig14mo ago
No description
No description
Brody
Brody14mo ago
exactly what adam told you to do 😐
smaig
smaigOP14mo ago
I'm very ashamed that I didn't understand you
Brody
Brody14mo ago
to your credit, nixpacks should probably set saine min/max memory values for this
smaig
smaigOP14mo ago
I thought there was no need to change anything on the railway
Brody
Brody14mo ago
unfortunaly it seems like this has been overlooked a tad
smaig
smaigOP14mo ago
That's probably why it eats up a lot of memory
Brody
Brody14mo ago
indeed @jr possible room for improvement on the java provider?
smaig
smaigOP14mo ago
It is necessary to change the documentation for subsequent users, otherwise this is a significant flaw.
Brody
Brody14mo ago
lets see what jr says
jr
jr14mo 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
Adam14mo 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