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 ?
53 Replies
Project ID:
N/A
That is a lot of memory 👀
What does your ktor server do?
Your KTOR is using what engine? JVM?
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
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
Maybe u can manipulate jvm arguments to lower the max and minimum ram it uses, just my thought tho, since its a consistent usage
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.
There are many different routes in the program , and I call them in the main function
^
This did not help the server for some reason still uses a large amount of memory @Brody
look into lowering the max amount of ram it can use
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?
I believe 2gb is the default, so your usage makes sense
I read about it and it interested me. I just don’t know where to change it, where to write it @Adam
It’ll be in your start command or as an env variable
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 thisok
I tried a lot and it doesn't work .
... 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 setting it as an .env var
JAVA_OPTS="-Xmx2G -Xms16M"
it doesn't work
I don 't understand why there is 8 GB of memory in my pocket , and I have to pay for them separately
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
Also, there's a Ktor template on railway
https://railway.app/template/zB6nSu
u can base urself on that one
Also, it seems they could set JVM options
https://github.com/richardamare/ktor-starter/blob/master/gradlew#L88
GitHub
ktor-starter/gradlew at master · richardamare/ktor-starter
Contribute to richardamare/ktor-starter development by creating an account on GitHub.
U can fork it and edit.
like this is it
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.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
I'm out of ideas
...i mean
I think I found it
new commit
yes its work
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
adam did tell you to do that, we thought you had already tried that
cool!
Solution
exactly what adam told you to do 😐
I'm very ashamed that I didn't understand you
to your credit, nixpacks should probably set saine min/max memory values for this
I thought there was no need to change anything on the railway
unfortunaly it seems like this has been overlooked a tad
That's probably why it eats up a lot of memory
indeed
@jr possible room for improvement on the java provider?
It is necessary to change the documentation for subsequent users, otherwise this is a significant flaw.
lets see what jr says
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
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