Ktor: Heroku deployment

Created on 11 Sep 2017  路  7Comments  路  Source: ktorio/ktor

Hello,
I am using Ktor for about a month, and I want to deploy it on Heroku.
I am using Gradle, but it keeps running out of memory when building on the server instance.
I know this is far unrelated to Ktor, but It would be much helpful if there is a post,
or a video, that shows how to deploy on Heroku and fine-tuning Gradle build memory.

2017-09-10T22:13:24.411340+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-jetty/0.4.0/ktor-jetty-0.4.0.jar
2017-09-10T22:13:24.489633+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-locations/0.4.0/ktor-locations-0.4.0.jar
2017-09-10T22:13:24.557579+00:00 app[web.1]: Download https://jcenter.bintray.com/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
2017-09-10T22:13:24.619967+00:00 app[web.1]: Download https://jcenter.bintray.com/com/google/code/gson/gson/2.8.1/gson-2.8.1.jar
2017-09-10T22:13:24.690789+00:00 app[web.1]: Download https://jcenter.bintray.com/joda-time/joda-time/2.9.9/joda-time-2.9.9.jar
2017-09-10T22:13:24.777056+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/exposed/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.jar
2017-09-10T22:13:24.910833+00:00 app[web.1]: Download https://jcenter.bintray.com/com/h2database/h2/1.4.196/h2-1.4.196.jar
2017-09-10T22:13:25.016004+00:00 app[web.1]: Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.4-2/kotlin-stdlib-jre7-1.1.4-2.jar
2017-09-10T22:13:25.110782+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-hosts-common/0.4.0/ktor-hosts-common-0.4.0.jar
2017-09-10T22:13:25.188960+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-servlet/0.4.0/ktor-servlet-0.4.0.jar
2017-09-10T22:13:25.261784+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-server/9.4.6.v20170531/jetty-server-9.4.6.v20170531.jar
2017-09-10T22:13:25.354210+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-servlets/9.4.6.v20170531/jetty-servlets-9.4.6.v20170531.jar
2017-09-10T22:13:25.409480+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-alpn-server/9.4.6.v20170531/jetty-alpn-server-9.4.6.v20170531.jar
2017-09-10T22:13:25.464805+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/http2/http2-server/9.4.6.v20170531/http2-server-9.4.6.v20170531.jar
2017-09-10T22:13:25.580746+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-core/0.4.0/ktor-core-0.4.0.jar
2017-09-10T22:13:25.778034+00:00 app[web.1]: Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.4/kotlin-reflect-1.1.4.jar
2017-09-10T22:13:25.851761+00:00 app[web.1]: Download https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-coroutines-jdk8/0.17/kotlinx-coroutines-jdk8-0.17.jar
2017-09-10T22:13:25.916693+00:00 app[web.1]: Download https://jcenter.bintray.com/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar
2017-09-10T22:13:25.992860+00:00 app[web.1]: Download https://jcenter.bintray.com/com/typesafe/config/1.3.1/config-1.3.1.jar
2017-09-10T22:13:26.118605+00:00 app[web.1]: Download http://dl.bintray.com/kotlin/ktor/org/jetbrains/ktor/ktor-auth/0.4.0/ktor-auth-0.4.0.jar
2017-09-10T22:13:26.194937+00:00 app[web.1]: Download https://jcenter.bintray.com/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar
2017-09-10T22:13:26.271935+00:00 app[web.1]: Download https://jcenter.bintray.com/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
2017-09-10T22:13:26.352141+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-http/9.4.6.v20170531/jetty-http-9.4.6.v20170531.jar
2017-09-10T22:13:26.419922+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-io/9.4.6.v20170531/jetty-io-9.4.6.v20170531.jar
2017-09-10T22:13:26.483115+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-continuation/9.4.6.v20170531/jetty-continuation-9.4.6.v20170531.jar
2017-09-10T22:13:26.561193+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/jetty-util/9.4.6.v20170531/jetty-util-9.4.6.v20170531.jar
2017-09-10T22:13:26.635438+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/http2/http2-common/9.4.6.v20170531/http2-common-9.4.6.v20170531.jar
2017-09-10T22:13:26.692746+00:00 app[web.1]: Download https://jcenter.bintray.com/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar
2017-09-10T22:13:26.761301+00:00 app[web.1]: Download https://jcenter.bintray.com/org/eclipse/jetty/http2/http2-hpack/9.4.6.v20170531/http2-hpack-9.4.6.v20170531.jar
2017-09-10T22:13:26.837263+00:00 app[web.1]: Download https://jcenter.bintray.com/junit/junit/4.10/junit-4.10.jar
2017-09-10T22:13:26.891110+00:00 app[web.1]: Download https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar
2017-09-10T22:13:27.107970+00:00 app[web.1]: Using kotlin incremental compilation
2017-09-10T22:13:35.452429+00:00 heroku[web.1]: Process running mem=693M(133.5%)
2017-09-10T22:13:35.452726+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2017-09-10T22:13:51.349580+00:00 app[web.1]: :compileJava UP-TO-DATE
2017-09-10T22:13:51.460589+00:00 app[web.1]: :copyMainKotlinClasses
2017-09-10T22:13:51.738049+00:00 app[web.1]: :processResources
2017-09-10T22:13:51.740250+00:00 app[web.1]: :classes
2017-09-10T22:13:52.026062+00:00 app[web.1]: :jar
2017-09-10T22:13:52.514525+00:00 app[web.1]: :startScripts
2017-09-10T22:13:52.819342+00:00 app[web.1]: :distTar
2017-09-10T22:13:54.436663+00:00 app[web.1]: :distZip
2017-09-10T22:13:57.636714+00:00 heroku[web.1]: Process running mem=793M(155.0%)
2017-09-10T22:13:57.636945+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2017-09-10T22:14:01.787160+00:00 app[web.1]: :shadowJar
2017-09-10T22:14:01.853661+00:00 app[web.1]: :startShadowScripts
2017-09-10T22:14:01.976728+00:00 app[web.1]: :shadowDistTar
2017-09-10T22:14:02.593865+00:00 app[web.1]: :shadowDistZip
2017-09-10T22:14:02.594918+00:00 app[web.1]: :assemble
2017-09-10T22:14:02.598841+00:00 app[web.1]: :compileTestKotlin UP-TO-DATE
2017-09-10T22:14:02.599871+00:00 app[web.1]: :compileTestJava UP-TO-DATE
2017-09-10T22:14:02.604608+00:00 app[web.1]: :copyTestKotlinClasses
2017-09-10T22:14:02.606123+00:00 app[web.1]: :processTestResources UP-TO-DATE
2017-09-10T22:14:02.606581+00:00 app[web.1]: :testClasses UP-TO-DATE
2017-09-10T22:14:02.626156+00:00 app[web.1]: :test UP-TO-DATE
2017-09-10T22:14:02.627769+00:00 app[web.1]: :check UP-TO-DATE
2017-09-10T22:14:02.627894+00:00 app[web.1]: :build
2017-09-10T22:14:02.639585+00:00 app[web.1]: 
2017-09-10T22:14:02.639884+00:00 app[web.1]: BUILD SUCCESSFUL
2017-09-10T22:14:02.640076+00:00 app[web.1]: 
2017-09-10T22:14:02.640299+00:00 app[web.1]: Total time: 1 mins 11.929 secs
2017-09-10T22:14:03.312499+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
2017-09-10T22:14:04.184513+00:00 app[web.1]: 22:14:04.181 [main] INFO  org.eclipse.jetty.util.log - Logging initialized @863ms to org.eclipse.jetty.util.log.Slf4jLog
2017-09-10T22:14:04.393010+00:00 app[web.1]: 22:14:04.392 [main] INFO  ktor.application - No ktor.deployment.watch patterns specified, automatic reload is not active
2017-09-10T22:14:06.329446+00:00 app[web.1]: 22:14:06.329 [main] TRACE ktor.application - Application started: org.jetbrains.ktor.application.Application@2a5b3fee
2017-09-10T22:14:06.336480+00:00 app[web.1]: 22:14:06.336 [main] INFO  org.eclipse.jetty.server.Server - jetty-9.4.z-SNAPSHOT
2017-09-10T22:14:06.551205+00:00 app[web.1]: 22:14:06.550 [main] INFO  o.e.jetty.server.AbstractConnector - Started ServerConnector@7a7333aa{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080}
2017-09-10T22:14:06.551477+00:00 app[web.1]: 22:14:06.551 [main] INFO  org.eclipse.jetty.server.Server - Started @3239ms
2017-09-10T22:14:18.295752+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2017-09-10T22:14:18.295752+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-09-10T22:14:18.477851+00:00 heroku[web.1]: Process exited with status 137
2017-09-10T22:14:18.490771+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-10T22:14:20.149480+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/latest" host=hawajes.herokuapp.com request_id=34007d55-8603-455a-9f2f-359655891b6a fwd="37.236.18.126" dyno= connect= service= status=503 bytes= protocol=https
2017-09-10T22:14:21.028044+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hawajes.herokuapp.com request_id=dfc5a68d-6972-4f9e-aeac-4eb1a19ea4a3 fwd="37.236.18.126" dyno= connect= service= status=503 bytes= protocol=https

All 7 comments

I don't see anything about out of memory in the log, it says

Web process failed to bind to $PORT within 90 seconds of launch

Please follow Heroku's own guide: https://devcenter.heroku.com/articles/getting-started-with-kotlin#introduction

what about

2017-09-10T22:13:35.452429+00:00 heroku[web.1]: Process running mem=693M(133.5%)
2017-09-10T22:13:35.452726+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)

?
thanks any way...

It looks like a message from heroku, not JVM. Try looking for this specific error on Heroku site. If you will not be able to find a solution, please comment here, we'll try to talk to Heroku people.

@bluemix it looks like you are running a gradle command in your Procfile. Is that correct? If so, that's not what you want to do in a production environment (because the Gradle cache and .m2 dir will not be available). Instead, you need to package any JARs or binaries you need into your build/ directory and run the app with a java -jar or java -cp command in your Procfile.

@jkutner , yes, exactly, I am running ./gradlew run.
Ah, I actually thought of running the executable version instead of building it, but the problem didn't happened to me on DigitalOcean, so, I though that Gradle was taking too much memory when building.

Thanks a lot for your reply 馃憤
@orangy I'll try to create an article about Ktor deployment on Heroku 馃檪

@bluemix If you want an example of how to do a Heroku deployment, you can take a look at my project source code, specifically this gradle build file.

@ddsoyka that's great, thanks for sharing. But keep in mind that it uses the heroku-gradle plugin. @bluemix is currently using git push, which are different deployment mechanisms. Both are great and supported--only a matter of preference.

Was this page helpful?
0 / 5 - 0 ratings