49
1 #Dynatrace COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE Asad Ali, @AsadThoughts Java-Based Microservices

Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

Embed Size (px)

Citation preview

Page 1: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

1 #DynatraceCOMPANY CONFIDENTIAL – DO NOT DISTRIBUTE

Asad Ali, @AsadThoughts

Java-Based Microservices

Page 2: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

2 #DynatraceCOMPANY CONFIDENTIAL – DO NOT DISTRIBUTE

Topics

• Overview of Producer Consumer Pattern

• Usage of Producer Consumer Pattern @ Dynatrace AppMon

• Microservices & Producer Consumer Pattern

Page 3: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

3 #Dynatrace

Producer Consumer 2

Consumer 1

Consumer N

Work Queue

Producer Consumer Pattern

Page 4: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

4 #Dynatrace

Producer Consumer 2

Consumer 1

Consumer N

Collection

Work Queue

Producer Consumer Pattern

Page 5: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

5 #DynatraceCOMPANY CONFIDENTIAL – DO NOT DISTRIBUTE

Producer Consumer @ Dynatrace AppMon

Page 6: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

6 #Dynatrace

Dynatrace AppMon ArchitectureJava/.NET

PurePathCollector

dynaTraceServer

Web Server/ PHP

C++, VB, ADK

MQ/ESB

Page 7: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

7 #Dynatrace

Metrics sent by agents

Visits

Page 8: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

8 #Dynatrace

Producer Consumer 2

Consumer 1

Consumer N

Visit Store Collection

Work QueueCorrelation Engine

Real Time AnalyzerProducer Consumer Within AppMon

Page 9: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

9 #Dynatrace

Producer Consumer 2

Consumer 1

Consumer N

Visit Store Collection

Work Queue

Work Queue Getting Full

Problem Symptom

Page 10: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

10 #Dynatrace

Individual Transaction View

Page 11: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

11 #Dynatrace

Individual Transaction View

Page 12: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

12 #Dynatrace

46 threads are in Wait state

Thread Dump Analysis

Page 13: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

13 #Dynatrace

Performance Report

Page 14: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

14 #Dynatrace

Code Snippet

public synchronized void add(Visit visit) {Objects.requireNonNull(visit);super.add(visit);

}

public synchronized Visit get(int visitId) {return super.get(visitId);

}

Page 15: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

15 #Dynatrace

Code Snippet

public synchronized void add(Visit visit) {Objects.requireNonNull(visit);super.add(visit);

}

public synchronized Visit get(int visitId) {return super.get(visitId);

}

Exclusive lock on visitstore caused consumers

to wait on each other

Page 16: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

16 #Dynatrace

Optimized Code

public Visit get(int visitId) {final ReadLock readLock = rrwl.readLock();readLock.lock();try {

return super.get(visitId);} finally {

readLock.unlock();}

}

Page 17: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

17 #Dynatrace

Optimized Code

public void add(Visit visit) {Objects.requireNonNull(visit);final WriteLock writeLock = rrwl.writeLock();writeLock.lock();try {

size.incrementAndGet();super.add(visit);

} finally {writeLock.unlock();

}}

Page 18: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

18 #Dynatrace

Performance Report - Optimized

Page 19: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

19 #Dynatrace

Performance Report - Optimized

Page 20: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

20 #Dynatrace

Individual Transaction View - Optimized

Page 21: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

21 #Dynatrace

Individual Transaction View - Optimized

Page 22: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

22 #Dynatrace

Page 23: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

23 #Dynatrace

Lesson #1

Analyze response time of your transactions

Page 24: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

24 #Dynatrace

Lesson #2

public Visit get(int visitId) {final ReadLock readLock = rrwl.readLock();readLock.lock();try {

return super.get(visitId);} finally {

readLock.unlock();}

}

Parallelize reads

Page 25: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

25 #Dynatrace

Lesson #3

Compare before and afterresponse time and throughput

Page 26: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

26 #Dynatrace

Microservices & Producer Consumer Pattern

Page 27: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

27 #Dynatrace

Producer Consumer 2

Consumer 1

Consumer N

Work Queue

Producer Consumer Pattern

Page 28: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

28 #Dynatrace

JVM1

JVM

Producer

JMS

Producer Consumer With MicroservicesConsumer 1

JVM2

Consumer 2

JVMn

Consumer N

Page 29: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

29 #Dynatrace

Producer Consumer With Microservices

JMS JVM1

Consumer 1

JVM

ProducerJVM2

Consumer 2

JVMn

Consumer N

Page 30: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

30 #Dynatrace

Monolithic Application

Page 31: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

31 #Dynatrace

2.68s Load Time

Monolithic Application

Page 32: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

32 #Dynatrace

2.68s Load Time

94.09% CPU Bound

Monolithic Application

Page 33: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

33 #Dynatrace

Can‘t scale vertically endlessly!

2.68s Load Time

94.09% CPU Bound

Monolithic Application

Page 34: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

34 #Dynatrace

Frontendto Cloud

Scale Backendin Containers!

Service Approach

Page 35: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

35 #Dynatrace

Go Live - 7am

Page 36: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

36 #Dynatrace

Go Live - 12pm

Page 37: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

37 #Dynatrace

What Went Wrong?

Page 38: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

38 #Dynatrace

26.7s Load Time5kB Payload

Single Search Query End-to-End

Page 39: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

39 #Dynatrace

26.7s Load Time5kB Payload

33! Service Calls

99kB - 3kB for each call!

Single Search Query End-to-End

Page 40: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

40 #Dynatrace

26.7s Load Time5kB Payload

33! Service Calls

99kB - 3kB for each call!

Architecture ViolationDirect access to DB from frontend service

Single Search Query End-to-End

Page 41: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

41 #Dynatrace

26.7s Load Time5kB Payload

33! Service Calls

99kB - 3kB for each call!

171! Total SQL Count

Architecture ViolationDirect access to DB from frontend service

Single Search Query End-to-End

Page 42: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

42 #Dynatrace

The Fixed End-to-End Use Case

“Re-Architect” vs “Migrate” to Service-Orientation

2.5s (vs 26.7) 5kB Payload

Page 43: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

43 #Dynatrace

The Fixed End-to-End Use Case

“Re-Architect” vs “Migrate” to Service-Orientation

2.5s (vs 26.7) 5kB Payload

1! (vs 33!) Service Call

5kB (vs 99) Payload!

Page 44: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

44 #Dynatrace

The Fixed End-to-End Use Case

“Re-Architect” vs “Migrate” to Service-Orientation

2.5s (vs 26.7) 5kB Payload

1! (vs 33!) Service Call

5kB (vs 99) Payload!

3! (vs 177) Total SQL Count

Page 45: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

45 #Dynatrace

Page 46: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

46 #Dynatrace

Lesson #1

JMS JVM1

Consumer 1

JVM

ProducerJVM2

Consumer 2

JVMn

Consumer N

Pay attention to dependencies when using Microservices

Page 47: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

47 #Dynatrace

Lesson #2

Measure inter-tier communicationtime for every transaction

Page 48: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

48 #Dynatrace

Asad AliProduct Specialist

@AsadThoughts

http://blog.dynatrace.com

http://bit.ly/dtpersonal

Page 49: Java-Based Microservices: Understanding the Benefits and Boundaries for Your Application Structure

49 #Dynatrace

Over To You

• Power of producer consumer pattern• Parallelize your reads• Measure before and after • Affect of Inter-tier communication in

Microservices• Do not ignore dependencies