https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
s

spierce7

01/27/2023, 2:37 PM
Does anyone have any tips for decreasing app start times on the JVM? Ktor is fast for a JVM framework, but the JVM is pretty slow.
j

jw

01/27/2023, 2:42 PM
What's the goal? Start fast but be slower over the lifetime? Or start fast and stay fast? Or start fast and quit after 1 request? Something else?
d

Dominik Sandjaja

01/27/2023, 2:43 PM
You might be interested in GraalVM: https://ktor.io/docs/graalvm.html
j

jw

01/27/2023, 2:43 PM
You can use epsilon GC if you're short lived. You can use AppCDS to preload classes. You can use CIO instead of Jetty/Netty which doesn't take multiple seconds to start. You can disable C2 if you're short-lived.
s

spierce7

01/27/2023, 2:45 PM
@jw Fast start and stay fast - Running JVM Server in serverless environment.
@Dominik Sandjaja I paid a lot of attention to graalvm, but I've found maintaining it and getting everything working with it (especially netty) a HUGE pain. Almost worse than proguard.
d

Dominik Sandjaja

01/27/2023, 2:46 PM
[...] stay fast - Running [...] in serverless environment
Isn't this a bit of a contradiction? Isn't the whole idea to only handle a single request and then quickly shut down again?
s

spierce7

01/27/2023, 2:47 PM
@Dominik Sandjaja Take a look at https://cloud.google.com/run It automatically scales with your traffic. The Goal is to startup and then handle more concurrent requests until the traffic spike subsides.
You can use CIO instead of Jetty/Netty which doesn't take multiple seconds to start.
@jw This is interesting. I've been hesitant to use CIO, and stayed away from it because I assumed no one else was using it. Plus why would I use it when I could use something like Netty 😛 Maybe Netty is the problem though.
j

jw

01/27/2023, 2:49 PM
I use CIO but not for anything heavy. It much easier to make a minimal JRE with jlink using CIO than Jetty/Netty.
s

spierce7

01/27/2023, 2:53 PM
I guess the reason I'm not using GraalVM is because of Netty now that I think about it
CIO looks to have worse performance than netty, but I guess that's the tradeoff
d

Dominik Sandjaja

01/27/2023, 2:55 PM
I guess it makes sense to evaluate whether you do benefit from the performance benefits of a longer-running JVM vs. an amazingly quickly starting application. Depending on your usecase you could maybe even create two application variants, one for the longer running "baseline" and a graalVM based version that handles peak traffic. But this is now more an architectural discussion than a
ktor
one.
s

spierce7

01/27/2023, 2:58 PM
For now I'll give CIO a shot and also look into AppCDS.
c

Casey Brooks

01/27/2023, 3:07 PM
JB started working on a ktor-compatible serverless toolkit, Kotless, but it looks like it hasn’t been updated in a while. But it mentions (among other features) AWS Lambda auto-warming
j

jw

01/27/2023, 3:07 PM
that name physically hurts
p

psh

01/27/2023, 3:17 PM
Surely cant be any worse than the (circa 2016) “Gogland” that thankfully was renamed
a

Andrew O'Hara

01/27/2023, 3:56 PM
Here's some tips to keep serverless start times low. 1. Minimize JAR size. Eliminate bloated libraries like jackson, log4j, spring, guava, official aws sdk, and kotlin-reflect 2. Minimize config fetching. If your app needs to make external calls to get secrets and other config params, embed them as env variables instead 3. Optimize JVM AoT JiT compilation for cold-starts. Having fast start and fast run would be having your cake and eating it too. Set this env variable:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
4. I have no idea why and how you're running Netty in a Lambda to serve your traffic. You would ideally use an adapter to convert Ktor to the serverless programming model, without running an embedded server. This can apparently be done with Kotless (as shown above), but http4k's smaller footprint and modular architecture gives it an an edge in serverless environments. https://www.http4k.org/guide/reference/serverless/ 5. Eliminate reflection on app init. No AoP or DI tools (unless done at compile-time)
j

jw

01/27/2023, 3:58 PM
Optimize JVM AoT compilation for cold-starts.
This does not do anything for AOT. This is disabling C2. Both C1 and C2 are JIT compilers since they run at runtime, not ahead-of-time.
Both aspect-oriented and DI libraries can be used provided they run at compile-time and not runtime.
a

Andrew O'Hara

01/27/2023, 4:00 PM
This does not do anything for AOT
Yes. I meant JiT. Corrected.
Both aspect-oriented and DI libraries can be used provided they run at compile-time and not runtime.
Good point
s

spierce7

01/27/2023, 4:45 PM
I have no idea why and how you're running Netty in a Lambda to serve your traffic.
lol! I'm not. hahaha I'm using Cloud Run. Cloud run lets you run a docker container, and then it stays running. Cloud Run scales at the docker container level. IMO it's much better than something like functions or lambda.
Having fast start and fast run would be having your cake and eating it too.
It'd be nice if I could focus on fast starts, and then transition to fast run.
V8 does a pretty nice job of starting way faster than Java, and then having similar performance.
j

jw

01/27/2023, 4:52 PM
yeah it's unfortunate you can't stop at tier 1 for a while and then enable C2 (tier 4) after some period of time (60 seconds). You could set the tier 2 and 3 thresholds to be equal to tier 4 and then set tier 4 at some level that approximates the amount of time your container would be running at 100% load for some period of time
s

spierce7

01/27/2023, 4:54 PM
It looks like you can change VM parameters at runtime -
com.sun.management.HotSpotDiagnosticMXBean#setVMOption(String, String)
I don't know if it would actually have an effect
You could set the tier 2 and 3 thresholds to be equal to tier 4 and then set tier 4
@jw What thresholds?
j

jw

01/27/2023, 4:55 PM
it's basically the number of invocations before the next level of compilation kicks in
s

spierce7

01/27/2023, 4:56 PM
how do I set those?
j

jw

01/27/2023, 4:56 PM
if you set 1 to 0 (immediately JIT compile all methods with no profiling data) and 2, 3, and 4 to, say, 10,000 (or some number) then C2 which is the most advanced JIT compilation
uhhhhh -Xint:Tier2Compilation=10000?
i have to google
s

spierce7

01/27/2023, 4:56 PM
I'll google for it
j

jw

01/27/2023, 4:57 PM
s

spierce7

01/27/2023, 4:57 PM
interesting, I remember reading about this a while back
I've been reading about this for a while. I'm really surprised how I can't find actual documentation for this. I'm trying to understand the difference between
CompileThreshold
and
Tier2CompileThreshold
. For some reason
CompileThreshold
default is 10k, but
Tier2CompileThreshold
default is 0 with
Tier3CompileThreshold
at 2k.
Tier1CompileThreshold
doesn't exist, and based on the defaults, I'd assume that
CompileThreshold
isn't Tier1.
@jw So I could do:
Tier2CompileThreshold=10000
Tier3CompileThreshold=10000
Tier4CompileThreshold=10000
But how would I set Tier1 to 0? Based on the defaults, it seems like
CompileThreshold
is not Tier1.
j

jw

01/27/2023, 5:55 PM
I'm not sure. Maybe it can't be controlled? Or maybe it kicks in right away anyway?
s

spierce7

01/28/2023, 5:29 AM
It looks like Netty finally fixed their graalvm issue yesterday - https://github.com/netty/netty/pull/13158