48
Automated Scaling of Microservice Stacks for JavaEE Applications by Ihor Kolodyuk

Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Embed Size (px)

Citation preview

Page 1: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Automated Scaling of Microservice Stacks for

JavaEE Applications

by Ihor Kolodyuk

Page 2: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Few words about me …

Driving technology direction at Jelastic

Like to solve unsolvable problems

Checking technology concepts on practice

Page 3: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Why I am here?

I want to talk to you about:

General autoscaling concept for JavaEE applications

Real use cases. Real issues. Tricky things

My goals are:

Save your time if you decide you need to scale your app

Share our own experience

Page 4: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

I just deploy my application to Docker, set a number of replicas and … have it running … bla bla bla … super easy! Done!

The myth

Page 5: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Yes, pretty easy …

If you need a super scalable and clustered Hello World application …

Page 6: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

In real life with JavaEE application we have architecture similar to this

and its autoscaling becomes not a very trivial task…

Page 7: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

The truth

Legacy Application

Scalable Cluster

Autoscalable Cluster

Page 8: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Theoretical part

Page 9: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

At least 3 key things to make your applications scalable

Page 10: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

First:Adapted runtime

(Container + JVM + JavaEE Server)

micro

Page 11: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Preferably, thin versions of application servers

YES!NO!

Page 12: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

microglassfish

There are various versions adapted for lightweight containers

Page 13: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Any specific reason to use VMs for microservices?

NO!

Page 14: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Well…it might be, but …

Page 15: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

What should we use instead?

YES!

Page 16: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

One container - one microservice instance

YES! NO!

Page 17: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Second:Application

prepared for microservices

APPMS

MS MS

MS

Page 18: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

SORRY, Application

prepared for SCALABLE microservices

Page 19: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Next few slides can be a bit boring for those who know…

BUT

Still important!!!!!!

Page 20: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Ideal scaling and decomposition

horizontal

verti

cal

topolo

gy

Page 21: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Decomposition into microservice

At least 2 key approaches

Page 22: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Logical division

Page 23: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Splitting bigger parts into smaller

1. Analyse metrics (NewRelic / JavaVisualVM)

2. Find a weak point (!)

3. Move this part to microservice

4. Repeat

Page 24: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Third:Orchestration software

Page 25: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

What it typically does?

CONTAINERSPROVISIONING

HEALTHCHECKS

METRICSGATHERING

APPLICATION LIFECYCLEMANAGEMENT

SCALING

AUTOMATIC LOADBALANCING

SERVICE DISCOVERY&CONNECTIVITY

CUSTOM SCRIPTING*

Page 26: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical triggers that are used for scaling

CPU RAM

HDD(disk I/O) NETWORK

SERVICEFAILURE SCHEDULER

Page 27: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Practical part

Tricky things

Typical issues

Examples

Page 28: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Tricky thing #1

In which direction to scale?

horizontal

verti

cal

topolo

gy

Page 29: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Example #1Message Queue Service

Triggers configuration

CPURAMHDD (disk I/O)NETWORKSCHEDULER YES

NOPROBABLY NO

GENERAL SETGENERAL SET

Scaling type HORIZONTAL

Tricky place

Page 30: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Example #2Databases

CPURAMHDD (disk I/O)NETWORKSCHEDULER

YES

VERTICAL

NO

NONO

Scaling type

Triggers configuration

YES

Page 31: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical issues while scaling of database instances

Takes much time to sync data

Temporary locks

Temporary performance degradation

Hard to use auto horizontal scaling Automatic vertical scaling can be used just fine It’s better to keep spare instances underloaded

(dedicated storage per instance)

RESUME

Page 32: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Example #3Legacy JavaEE application

TOPOLOGY

Java EE Server

Business Tier

Web Tier

JSP App1 JSP App2 JSP App2

EJB App1 EJB App2

Java EE Micro Instance

JSP App1

Java EE Micro Instance

JSP App1

Java EE Micro Instance

JSP App1Java EE

Micro Instance

JSP App1

Java EE Micro Instance

JSP App1

Java EE Micro Instance

JSP App2

Java EE Micro Instance

JSP App1

Java EE Micro Instance

JSP App1

Java EE Micro Instance

EJB App2Java EE

Micro Instance

JSP App1

Java EE Micro Instance

JSP App1

Java EE Micro Instance

EJB App2

Scaling type

Page 33: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Tricky thing #2

Events subscription

Usually, just spinning up an extra instance is NOT enough

Page 34: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Example #1Typical ScaleIn/ScaleOut events and cases

onAfterScaleOut[nodeGroup:ejb-app1] { “call”: “registerNodeInMonitoringSystem”, “call”: “addMemberToHazelcast”,

“call”: “call3rdPartyApiService”

}

onAfterScaleIn[nodeGroup:jsp-app2] { “call”: “removeNodeFromMonitoringSystem”, “call”: “removeMemberFromHazelcast” }

THE FULL WORKING AND MORE COMPLEX CODE EXAMPLE CAN BE FOUND HERE

Page 35: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Example #2

2. Get auth keys by instance before joining DASonBeforeStartService[nodeGroup:instance] { “cmd”: “/root/scripts/pullAccessKeys.sh ${token}” }

THE FULL WORKING AND MORE COMPLEX CODE EXAMPLE CAN BE FOUND HERE

1. Decrypt encrypted volume, that was attached on-fly

onAfterVolumeAttached[nodeGroup:instance] { “call”: “decryptVolume” }

3. Deprovision node from DAS if cluster was shrinked

onAfterScaleOut[nodeGroup:das] { “cmd”: “./asadmin_proxy remove ${instance[@last].ip}” }

Page 36: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Tricky thing #3Proper triggers configuration

This tuning is a long process, so be patient

Page 37: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical problem #1

Changing the value in one place can be reflected in other places

Page 38: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

How to deal with this?

Load Testing

Gathering

Metrics

Detect deviations in a testing loop

Analyz

ing

Metrics

Edit

Trigg

ersCompare previous

results

Page 39: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical problem #2The triggers can become outdated with new code

Page 40: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

The fix is easy here

Inject metrics collection as a part of your CI/CD step

COMMIT BUILD TESTING PERFORMANCEANALYSIS DELIVERY

Page 41: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Tricky thing #4Getting rid of spare things

Page 42: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical problem #1Network is full of useless traffic

Total bandwidth Multicast | HeartbeatsUseful traffic

Page 43: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

What we can do?

Avoid multicast (for members detection) Use events and static members lists

Static members list Static members list Static members list

Orchestrator

Page 44: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

Typical problem #2Some of JavaEE Servers are designed for VMs, not for containers

On example of Weblogic

VM VM VM VM

Page 45: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

What is the right way to go?Just remove everything spare

Page 46: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

LIVE demo comes here

Page 47: Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017

QUESTIONS