51
Deploying Scaleable JVM Apps on Heroku Joe Kutner JVM Languages Owner at Heroku @codefinger

Creating Scalable JVM/Java Apps on Heroku

Embed Size (px)

Citation preview

Page 1: Creating Scalable JVM/Java Apps on Heroku

Deploying Scaleable JVM Apps on HerokuJoe Kutner JVM Languages Owner at Heroku @codefinger

Page 2: Creating Scalable JVM/Java Apps on Heroku

Java Scala

Groovy Clojure JRuby

Page 3: Creating Scalable JVM/Java Apps on Heroku

.war

Traditional WAR file deployment…

Page 4: Creating Scalable JVM/Java Apps on Heroku

Why WAR?

Page 5: Creating Scalable JVM/Java Apps on Heroku

Use to introduce a

demo, video, Q&A, etc.

What does modern Java deployment look like?

Page 6: Creating Scalable JVM/Java Apps on Heroku

Modern Java deployment is…

Containerless

Page 7: Creating Scalable JVM/Java Apps on Heroku

Modern containerless deployment…

Page 8: Creating Scalable JVM/Java Apps on Heroku
Page 9: Creating Scalable JVM/Java Apps on Heroku

Let’s see it in action…

Page 10: Creating Scalable JVM/Java Apps on Heroku

java -jar myapp.jar

Page 11: Creating Scalable JVM/Java Apps on Heroku

java -jar jetty-runner.jar /my/app/

Page 12: Creating Scalable JVM/Java Apps on Heroku

$ heroku deploy:war myapp.war

Page 13: Creating Scalable JVM/Java Apps on Heroku

Use to introduce a

demo, video, Q&A, etc. The Twelve Factor App

Page 14: Creating Scalable JVM/Java Apps on Heroku

The Twelve Factor App is…• a manifesto • a methodology • a collection of experiences

Page 15: Creating Scalable JVM/Java Apps on Heroku

Its goals are…• scalability • maintainability • portability

Page 16: Creating Scalable JVM/Java Apps on Heroku

Its does this through…declarative setup …explicit dependencies …external configuration

!clean contracts …between your app and its platform …reduced coupling !minimum divergence …between each deployment …between dev and prod environments

Page 17: Creating Scalable JVM/Java Apps on Heroku

• Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

Twelve Factors

• Codebase • Dependencies • Config • Backing services • Build, release, run • Processes

12factor.net

Page 18: Creating Scalable JVM/Java Apps on Heroku

I. CodebaseOne codebase, many deploys

Test

Staging

Production

Page 19: Creating Scalable JVM/Java Apps on Heroku

I. CodebaseOne codebase, many deploys

Test

Staging

Production

$ git push heroku-test master

$ git push heroku-stg master

$ git push heroku-prod master

Page 20: Creating Scalable JVM/Java Apps on Heroku

II. DependenciesExplicitly declared

Page 21: Creating Scalable JVM/Java Apps on Heroku

II. DependenciesExplicitly declared

<dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> </dependency>

Page 22: Creating Scalable JVM/Java Apps on Heroku

II. DependenciesExplicitly declared

!libraryDependencies ++= Seq( "postgresql" % "postgresql" % "9.0-801.jdbc4" )

Page 23: Creating Scalable JVM/Java Apps on Heroku

II. DependenciesExplicitly declared

<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> </dependency>

Page 24: Creating Scalable JVM/Java Apps on Heroku

II. DependenciesExplicitly declared

libraryDependencies ++= Seq( "com.twitter" % "finagle-http" % "6.18.0", )

Page 25: Creating Scalable JVM/Java Apps on Heroku

III. ConfigurationStore config in the environment, not the app

Page 26: Creating Scalable JVM/Java Apps on Heroku

III. ConfigurationStore config in the environment, not the app

! <dbUrl>jdbc://postgres...</dbUrl>

Page 27: Creating Scalable JVM/Java Apps on Heroku

III. ConfigurationStore config in the environment, not the app

URI dbUri = new URI(System.getenv(“DATABASE_URL"));!

Page 28: Creating Scalable JVM/Java Apps on Heroku

III. ConfigurationStore config in the environment, not the app

$ heroku config:set JAVA_OPTS=“-Xmx512m”

Page 29: Creating Scalable JVM/Java Apps on Heroku

IV. Backing ServicesTreat backing services as attachable resources

Page 30: Creating Scalable JVM/Java Apps on Heroku

IV. Backing ServicesTreat backing services as attachable resources

Page 31: Creating Scalable JVM/Java Apps on Heroku

IV. Backing ServicesTreat backing services as attachable resources

$ heroku addons:add papertrail

Page 32: Creating Scalable JVM/Java Apps on Heroku

V. Build, release, run• A build step vendors dependencies, prepares assets, etc. • A release step creates a package from build and config. • A runtime step executes, without special knowledge.

Page 33: Creating Scalable JVM/Java Apps on Heroku

V. Build, release, run

$ mvn package

Page 34: Creating Scalable JVM/Java Apps on Heroku

V. Build, release, run

$ git push heroku master

Page 35: Creating Scalable JVM/Java Apps on Heroku

V. Build, release, run

$ sbt stage deployHeroku

Page 36: Creating Scalable JVM/Java Apps on Heroku

VI. ProcessesStateless

Page 37: Creating Scalable JVM/Java Apps on Heroku

VI. ProcessesStateless

Don’t write to the local filesystem.

Page 38: Creating Scalable JVM/Java Apps on Heroku

VII. Port binding• Export services via port binding • Self-contained, not relying on runtime injection by a web server

java -Dserver.port=$PORT -jar …

Page 39: Creating Scalable JVM/Java Apps on Heroku

VIII. Concurrency• Scale out • Scale up

Page 40: Creating Scalable JVM/Java Apps on Heroku

VIII. Concurrency• Scale out • Scale up

$ heroku ps:scale web=3

Page 41: Creating Scalable JVM/Java Apps on Heroku

VIII. Concurrency

web.1

web.2

worker.1 clock.1

Workload Diversity

Num

ber o

f Pro

cess

es

worker.2

worker.3

Page 42: Creating Scalable JVM/Java Apps on Heroku

IX. DisposabilityFast startup and graceful shutdown • Spring Boot and Play do this for you… • as opposed to big App Servers that take several minutes to boot

Page 43: Creating Scalable JVM/Java Apps on Heroku

X. Dev/prod parityKeep dev, staging, prod and everything in between as similar as possible

Page 44: Creating Scalable JVM/Java Apps on Heroku

X. Dev/prod parityKeep dev, staging, prod and everything in between as similar as possible

dev!

sqlite!

postgres

stage!

mysql!

postgres

prod!

postgres!

postgres

=!

≠!

=

=!

≠!

=

Page 45: Creating Scalable JVM/Java Apps on Heroku

XI. LogsTreat logs as event streams

Page 46: Creating Scalable JVM/Java Apps on Heroku

XI. LogsTreat logs as event streams

2014-09-10T22:38:43.427311+00:00 heroku[worker]: ... 2014-09-10T22:38:49.629790+00:00 heroku[web.1]: Starting process... 2014-09-10T22:39:22.056033+00:00 heroku[router]: at=info method=... 2014-09-10T22:38:43.427311+00:00 heroku[postgres]: ... 2014-09-10T22:38:43.427311+00:00 heroku[api]: Release v34 created... 2014-09-10T22:38:49.629790+00:00 heroku[web.1]: Starting process ... 2014-09-10T22:39:22.056033+00:00 heroku[router]: GET mysite.com/ ...

Event Stream

DB Web Worker

Page 47: Creating Scalable JVM/Java Apps on Heroku

XII. Admin ProcessesAdmin and management tasks should be one-off processes

Page 48: Creating Scalable JVM/Java Apps on Heroku

XII. Admin ProcessesAdmin and management tasks should be one-off processes

web1

web2

web3

admin

Page 49: Creating Scalable JVM/Java Apps on Heroku

• Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

Twelve Factors• Codebase • Dependencies • Config • Backing services • Build, release, run • Processes

Page 50: Creating Scalable JVM/Java Apps on Heroku

Further reading…!Heroku DevCenter: devcenter.heroku.com !Spring Boot Example: https://github.com/kissaten/spring-boot-executable !Link to slideshare !Twitter: @codefinger

Page 51: Creating Scalable JVM/Java Apps on Heroku

Thank You!Joe Kutner JVM Languages Owner at Heroku @codefinger