SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Tracing distributed service
calls: implementing APM
for the JVM
Disclaimer
I am contracting for the APM vendor Instana and gained most of my experience
working with APM while being with the company. In order to discuss what I have
been factually working with, I cannot avoid showcasing the tool I helped to make.
I am not paid to feature Instana in this presentation.
I. Inventory
II. Tracing (micro-)services
III. Implementing APM
IV. Advanced topics
Outline
Where we are coming from: the “distributed monolith”.
EAR EAR EAR EAR EAR EAR
node A node B node C
Where we are coming from: distribution by cloning.
Sources: Pictures by IBM and Oracle blogs.
Where we are coming from: inferred tracing.
Use of standard APIs: limits development to app server’s capabilities.
Sacrifice freedom in development but ease operation.
Standard APIs allow server to interpret program semantics.
Sources: Picture by IBM blog.
Where we transition to: greenfield “micro”-services.
JAR JAR JAR JAR JAR JAR
service A service B service C
HTTP/protobuf HTTP/protobuf
Sources: Lagom is a Lightbend trademark, Spring Boot is a Pivotal trademark.
Where we transition to: “The wheel of doom”
Twitter Hailo The Empire
Simple bits, complex interaction: death star topologies.
Sources: Screenshots from Zipkin on Twitter Blog and Hailo Blog. Death Star by “Free Star Wars Fan Art Collection”.
Where we transition to: simple services, complex operation.
1. Writing distributed services can ease development but adds challenges on integration.
2. Distributed services without standardized APIs cannot easily be observed in interaction.
3. Distributed services make it harder to collect structured monitoring data.
4. Distributed (micro-)services require DevOps to successfully run in production.
Sources: Picture by Reddit.
JAR JAR
The next big thing: serverless architecture?
JAR JAR JAR JAR
dispatcher A dispatcher B dispatcher C
Sources: AWS Lambda is an Amazon trademark.
The next big thing: serverless architecture?
Sources: Picture by Golden Eagle Coin. Concept from: “silver bullet syndrome” by Hadi Hariri.
silver bullet syndrome
I. Inventory
II. Tracing (micro-)services
III. Implementing APM
IV. Advanced topics
Outline
trace collector
192.168.0.2/bar.jar – uid(B)
0ms
What information do we want?
192.168.0.1/foo.jar 192.168.0.2/bar.jar 192.168.0.3/MySQL
HTTP JDBC
77.44.250.1
HTTP
uid(A)
192.168.0.1/foo.jar – uid(A)
192.168.0.2 – uid(A)
192.168.0.3/MySQL – uid(B)
100ms 200ms
entry exit entry exit
uid(A) uid(B)
192.168.0.2/bar.jar – uid(B)uid(A) uid(A)
How do we get it?
cs sr ss cr
span
trace
192.168.0.1/foo.jar – uid(A)
192.168.0.3/MySQL – uid(B)
192.168.0.2/bar.jar – uid(B)uid(A) uid(A)
{ query = select 1 from dual } annotation
Source: Logo from zipkin.io.
How do we get it?
Source: Zipkin screenshot.
Span.Builder span = Span.builder()
.traceId(42L)
.name("foo")
.id(48L)
.timestamp(System.currentTimeMillis());
long now = System.nanoTime();
// do hard work
span = span.duration(System.nanoTime() - now);
// send span to server
How do we get it?
Several competing APIs:
1. Most popular are Zipkin (core) and Brave.
2. Some libraries such as Finagle (RPC) offer built-in Zipkin-compatible tracing.
3. Many plugins exist to add tracing as a drop-in to several libraries.
4. Multiple APIs exist for different non-JVM languages.
A standard to the rescue.
Source: Logo from opentracing.io.
Span span = tracer.buildSpan("foo")
.asChildOf(parentSpan.context())
.withTag("bar", "qux")
.start();
// do hard work
span.finish();
A standard to the rescue.
Source: “Standards” by xkcd.
Problems:
1. Single missing element in chain breaks entire trace.
2. Requires explicit hand-over on every context switch.
(Span typically stored in thread-local storage.)
I. Inventory
II. Tracing (micro-)services
III. Implementing APM
IV. Advanced topics
Outline
Drop-in tracing.
public class TracingAgent {
public static void premain(String arg, Instrumentation inst) {
inst.addTransformer(
(classLoader, typeName, type, pd, classFile) -> {
if (shouldTraceClass(typeName)) {
return addTracing(classFile);
} else {
return null;
}
});
}
private static boolean shouldTraceClass(String typeName) {
return false; // TODO: implement
}
private static byte[] addTracing(byte[] binary) {
return binary; // TODO: implement
}
}
High-level instrumentation with Byte Buddy.
Code generation and manipulation library:
1. Apache 2.0 licensed.
2. Mature: Over 2 million downloads per year.
3. Requires zero byte-code competence.
4. Safe code generation (no verifier errors).
5. High-performance library (even faster than vanilla-ASM).
6. Already supports Java 9 (experimental).
7. Offers fluent API and type-safe instrumentation.
Check out http://bytebuddy.net and https://github.com/raphw/byte-buddy
class Foo {
String bar() { return "bar"; }
}
assertThat(new Foo().bar(), is("Hello World!"));
public static void premain(String argument,
Instrumentation instrumentation) {
new AgentBuilder.Default()
.type(named("Foo"))
.transform( (builder, type, classLoader) ->
builder.method(named("bar"))
.intercept(value("Hello World!"));
)
.installOn(instrumentation);
}
Java agents with Byte Buddy
class ServletAdvice {
@OnMethodEnter
static void enter(@Argument(0) HttpServletRequest request) {
String traceId = request.getHeader("X-Trace-Id");
String method = request.getMethod();
String uri = request.getRequestURI();
if (traceId != null) {
ServletTracer.continueTrace(traceId, method, uri);
} else {
ServletTracer.startTrace(method, uri);
}
}
@OnMethodExit
static void exit(@Argument(1) HttpServletResponse response) {
ServletTracer.complete(response.getStatusCode());
}
}
Inlining code with Byte Buddy advice
public class ServletTraceAgent {
public static void premain(String arg,
Instrumentation inst) {
new AgentBuilder.Default()
.type(isSubTypeOf(Servlet.class))
.transform( (builder, type, classLoader) ->
builder.visit(Advice.to(ServletAdvice.class)
.on(named("service")));
).installOn(inst);
}
}
Inlining code with Byte Buddy advice
public class ServletTraceAgent {
public static void agentmain(String arg,
Instrumentation inst) {
new AgentBuilder.Default()
.disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.type(isSubTypeOf(Servlet.class))
.transform( (builder, type, classLoader) ->
builder.visit(Advice.to(ServletAdvice.class)
.on(named("service")));
).installOn(inst);
}
}
Inlining code with Byte Buddy advice
APM architecture: example of Instana
JARJS
JARPHP
traces/metrics
metrics
traces
feedback
Trace view in Instana (example)
Logical view in Instana (example)
I. Inventory
II. Tracing (micro-)services
III. Implementing APM
IV. Advanced topics
Outline
(Adaptive) sampling
(Adaptive) sampling: events per second (without queue-bound)
(Adaptive) sampling: marketing “X% overhead”
class MyApp {
void foo() {
while (true) {
handleWebRequest();
}
}
}
class MyOtherApp {
void foo() {
while (true) {
Thread.sleep(100L);
}
}
}
JIT-friendly tracing
JIT-optimized
C CJava
incoming outgoing
-XX:MaxInlineSize=35 (auto-reduced)
-XX:FreqInlineSize=325
-XX:InlineSmallCode=2000
-XX:MaxInlineLevel=9
monomorphic bimorphic polymorphic megamorphic
direct link
vtable
lookup
(about 90%)
Most available tracers know three types of spans: client, server and local.
This often leads to “trace call megamorphism” in production systems.
optimization
deoptimization
home of rumors
conditional
direct link
(data structures) (but dominant targets)
JIT-friendly tracing: enforcing monomorphism
JIT-friendly tracing: copy&paste monomorphism
class ServletAdvice {
@OnMethodEnter
static void enter(@Argument(0) HttpServletRequest request) {
String traceId = request.getHeader("X-Trace-Id");
String method = request.getMethod();
String uri = request.getRequestURI();
if (traceId != null) {
ServletTracer.continueTrace(traceId, method, uri);
} else {
ServletTracer.startTrace(method, uri);
}
}
@OnMethodExit
static void exit(@Argument(1) HttpServletResponse response) {
ServletTracer.complete(response.getStatusCode());
}
}
Memory-friendly tracing
package com.twitter.zipkin.gen;
public class Span implements Serializable {
public volatile Long startTick;
private long trace_id;
private String name;
private long id;
private Long parent_id;
private List<Annotation> annotations = emptyList();
private List<BinaryAnnotation> b_annotations = emptyList();
private Boolean debug;
private Long timestamp;
private Long duration;
// ...
}
Memory-friendly tracing: Zero-garbage tracer
Span per event
Immutable events
Some privitives
Linked list attachments
Allocation rate correlates with events
Vulnerable to false-sharing
User-thread centric
Scala-style model
Span (container) per thread
Fully mutable events
All primitives (void ids)
Raw-data array annotations
Allocation rate correlates with sampled events
Ensures thread-locality
Tracer-thread centric
Java-style model
Span identification
incoming outgoing
class MyBatchFramework {
void doBatchJob() {
// do hard work...
}
}
@com.instana.sdk.Span("trace-me")
foo()
Context-switch tracing
incoming
outgoing
thread 1
thread 2
Requires explicit context hand-over upon each context-switch.
Tracing sandboxed applications
class AccessController {
public static void checkPermission(Permission permission)
throws AccessControlException {
AccessControlContext stack =
getStackAccessControlContext();
// perform check based on stack
}
class AccessController {
public static void checkPermission(Permission permission)
throws AccessControlException {
if (isInstanaSandboxed()) {
return;
}
AccessControlContext stack =
getStackAccessControlContext();
// perform check based on stack privileges
}
Testing instrumentation and trace collection
JAR
main(String[])TestCollector
Java 9: challenges ahead of us
ClassLoader.getSystemClassLoader()
.getResourceAsStream("java/lang/Object.class");
class MyServlet extends MyAbstractServlet
class MyAbstractServlet extends Servlet
Applies class hierarchy analysis without using reflection API!
(Cannot load types during instrumentation. Unless retransforming.)
Java 8
Java 9
URL
null
CHA is also required for inserting stack map frames. Byte Buddy allows for
on-the-fly translation of such frames. This way, Bytre Buddy is often faster
than vanilla ASM with frame computation enabled.
Byte Buddy automatically use loaded type reflection upon retransformation.
http://rafael.codes
@rafaelcodes
http://documents4j.com
https://github.com/documents4j/documents4j
http://bytebuddy.net
https://github.com/raphw/byte-buddy

Weitere ähnliche Inhalte

Was ist angesagt?

Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracerrahulrevo
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Anton Arhipov
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 

Was ist angesagt? (20)

Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Byte code field report
Byte code field reportByte code field report
Byte code field report
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracer
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
JVM
JVMJVM
JVM
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 

Andere mochten auch

Distributed Tracing with OpenTracing, ZipKin and Kubernetes
Distributed Tracing with OpenTracing, ZipKin and KubernetesDistributed Tracing with OpenTracing, ZipKin and Kubernetes
Distributed Tracing with OpenTracing, ZipKin and KubernetesContainer Solutions
 
Securing Your Deployment Pipeline With Docker
Securing Your Deployment Pipeline With DockerSecuring Your Deployment Pipeline With Docker
Securing Your Deployment Pipeline With DockerContainer Solutions
 
Pushing the hassle from production to developers. Easily
Pushing the hassle from production to developers. EasilyPushing the hassle from production to developers. Easily
Pushing the hassle from production to developers. EasilyMartin Gutenbrunner
 
Shared service centers - the future of enterprise service management - SEE 2016
Shared service centers - the future of enterprise service management - SEE 2016Shared service centers - the future of enterprise service management - SEE 2016
Shared service centers - the future of enterprise service management - SEE 2016TOPdesk
 
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...CA Technologies
 
The latest in Retain & GWAVA
The latest in Retain & GWAVAThe latest in Retain & GWAVA
The latest in Retain & GWAVAGWAVA
 
Beratungsunternehmen und Agilität - Manage Agile 2016
Beratungsunternehmen und Agilität - Manage Agile 2016Beratungsunternehmen und Agilität - Manage Agile 2016
Beratungsunternehmen und Agilität - Manage Agile 2016Frank Scheffler
 
IT Governance Framework
IT Governance FrameworkIT Governance Framework
IT Governance FrameworkSherri Booher
 
Modern Monitoring - devopsdays Cuba
Modern Monitoring - devopsdays CubaModern Monitoring - devopsdays Cuba
Modern Monitoring - devopsdays Cubabridgetkromhout
 
Lessons Learned - Monitoring the Data Pipeline at Hulu
Lessons Learned - Monitoring the Data Pipeline at HuluLessons Learned - Monitoring the Data Pipeline at Hulu
Lessons Learned - Monitoring the Data Pipeline at HuluDataWorks Summit
 
Shared Services Operating Models
Shared Services Operating ModelsShared Services Operating Models
Shared Services Operating ModelsYash Goyal
 
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...Organimi
 
Shared services centers sector 2016
Shared services centers sector 2016Shared services centers sector 2016
Shared services centers sector 2016ProColombia
 
Trace everything, when APM meets SysAdmins
Trace everything, when APM meets SysAdminsTrace everything, when APM meets SysAdmins
Trace everything, when APM meets SysAdminsSysdig
 
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...DynamicInfraDays
 
Initiating IT Governance Strategy to Identify Business Needs
Initiating IT Governance Strategy to Identify Business NeedsInitiating IT Governance Strategy to Identify Business Needs
Initiating IT Governance Strategy to Identify Business NeedsPECB
 
Supply Chain Management
Supply Chain ManagementSupply Chain Management
Supply Chain ManagementUNITY
 
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...Andreas Wagener
 

Andere mochten auch (20)

Distributed Tracing with OpenTracing, ZipKin and Kubernetes
Distributed Tracing with OpenTracing, ZipKin and KubernetesDistributed Tracing with OpenTracing, ZipKin and Kubernetes
Distributed Tracing with OpenTracing, ZipKin and Kubernetes
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
Securing Your Deployment Pipeline With Docker
Securing Your Deployment Pipeline With DockerSecuring Your Deployment Pipeline With Docker
Securing Your Deployment Pipeline With Docker
 
Pushing the hassle from production to developers. Easily
Pushing the hassle from production to developers. EasilyPushing the hassle from production to developers. Easily
Pushing the hassle from production to developers. Easily
 
Shared service centers - the future of enterprise service management - SEE 2016
Shared service centers - the future of enterprise service management - SEE 2016Shared service centers - the future of enterprise service management - SEE 2016
Shared service centers - the future of enterprise service management - SEE 2016
 
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...
Leading a Digital Business with Greater Agility: How to Plan a Modern Portfol...
 
The latest in Retain & GWAVA
The latest in Retain & GWAVAThe latest in Retain & GWAVA
The latest in Retain & GWAVA
 
Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
 
Beratungsunternehmen und Agilität - Manage Agile 2016
Beratungsunternehmen und Agilität - Manage Agile 2016Beratungsunternehmen und Agilität - Manage Agile 2016
Beratungsunternehmen und Agilität - Manage Agile 2016
 
IT Governance Framework
IT Governance FrameworkIT Governance Framework
IT Governance Framework
 
Modern Monitoring - devopsdays Cuba
Modern Monitoring - devopsdays CubaModern Monitoring - devopsdays Cuba
Modern Monitoring - devopsdays Cuba
 
Lessons Learned - Monitoring the Data Pipeline at Hulu
Lessons Learned - Monitoring the Data Pipeline at HuluLessons Learned - Monitoring the Data Pipeline at Hulu
Lessons Learned - Monitoring the Data Pipeline at Hulu
 
Shared Services Operating Models
Shared Services Operating ModelsShared Services Operating Models
Shared Services Operating Models
 
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...
Redrawing Org Charts; Rethinking Organizational Boundaries: Opportunities for...
 
Shared services centers sector 2016
Shared services centers sector 2016Shared services centers sector 2016
Shared services centers sector 2016
 
Trace everything, when APM meets SysAdmins
Trace everything, when APM meets SysAdminsTrace everything, when APM meets SysAdmins
Trace everything, when APM meets SysAdmins
 
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...
ContainerDays NYC 2016: "Observability and Manageability in a Container Envir...
 
Initiating IT Governance Strategy to Identify Business Needs
Initiating IT Governance Strategy to Identify Business NeedsInitiating IT Governance Strategy to Identify Business Needs
Initiating IT Governance Strategy to Identify Business Needs
 
Supply Chain Management
Supply Chain ManagementSupply Chain Management
Supply Chain Management
 
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...
Leben 4.0: Künstliche Intelligenz und der Weg in die Datengesellschaft. Vortr...
 

Ähnlich wie Monitoring distributed (micro-)services

Ato2019 weave-services-istio
Ato2019 weave-services-istioAto2019 weave-services-istio
Ato2019 weave-services-istioLin Sun
 
Weave Your Microservices with Istio
Weave Your Microservices with IstioWeave Your Microservices with Istio
Weave Your Microservices with IstioAll Things Open
 
All Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istioAll Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istioLin Sun
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop OverviewShubhra Kar
 
How do you create a programming language for the JVM?
How do you create a programming language for the JVM?How do you create a programming language for the JVM?
How do you create a programming language for the JVM?Federico Tomassetti
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
Hands on with CoAP and Californium
Hands on with CoAP and CaliforniumHands on with CoAP and Californium
Hands on with CoAP and CaliforniumJulien Vermillard
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesChris Bailey
 
Lessons Learnt from Running Thousands of On-demand Spark Applications
Lessons Learnt from Running Thousands of On-demand Spark ApplicationsLessons Learnt from Running Thousands of On-demand Spark Applications
Lessons Learnt from Running Thousands of On-demand Spark ApplicationsItai Yaffe
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Android RenderScript on LLVM
Android RenderScript on LLVMAndroid RenderScript on LLVM
Android RenderScript on LLVMJohn Lee
 
Managing Large-scale Networks with Trigger
Managing Large-scale Networks with TriggerManaging Large-scale Networks with Trigger
Managing Large-scale Networks with Triggerjathanism
 
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksAmazon Web Services
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonnettitude_labs
 

Ähnlich wie Monitoring distributed (micro-)services (20)

Ato2019 weave-services-istio
Ato2019 weave-services-istioAto2019 weave-services-istio
Ato2019 weave-services-istio
 
Weave Your Microservices with Istio
Weave Your Microservices with IstioWeave Your Microservices with Istio
Weave Your Microservices with Istio
 
All Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istioAll Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istio
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Java RMI
Java RMIJava RMI
Java RMI
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
How do you create a programming language for the JVM?
How do you create a programming language for the JVM?How do you create a programming language for the JVM?
How do you create a programming language for the JVM?
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
Hands on with CoAP and Californium
Hands on with CoAP and CaliforniumHands on with CoAP and Californium
Hands on with CoAP and Californium
 
ql.io at NodePDX
ql.io at NodePDXql.io at NodePDX
ql.io at NodePDX
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-ServicesNode Interactive: Node.js Performance and Highly Scalable Micro-Services
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
 
Lessons Learnt from Running Thousands of On-demand Spark Applications
Lessons Learnt from Running Thousands of On-demand Spark ApplicationsLessons Learnt from Running Thousands of On-demand Spark Applications
Lessons Learnt from Running Thousands of On-demand Spark Applications
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Android RenderScript on LLVM
Android RenderScript on LLVMAndroid RenderScript on LLVM
Android RenderScript on LLVM
 
Managing Large-scale Networks with Trigger
Managing Large-scale Networks with TriggerManaging Large-scale Networks with Trigger
Managing Large-scale Networks with Trigger
 
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-london
 

Kürzlich hochgeladen

Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 

Kürzlich hochgeladen (20)

Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 

Monitoring distributed (micro-)services

  • 1. Tracing distributed service calls: implementing APM for the JVM
  • 2. Disclaimer I am contracting for the APM vendor Instana and gained most of my experience working with APM while being with the company. In order to discuss what I have been factually working with, I cannot avoid showcasing the tool I helped to make. I am not paid to feature Instana in this presentation.
  • 3. I. Inventory II. Tracing (micro-)services III. Implementing APM IV. Advanced topics Outline
  • 4. Where we are coming from: the “distributed monolith”. EAR EAR EAR EAR EAR EAR node A node B node C
  • 5. Where we are coming from: distribution by cloning. Sources: Pictures by IBM and Oracle blogs.
  • 6. Where we are coming from: inferred tracing. Use of standard APIs: limits development to app server’s capabilities. Sacrifice freedom in development but ease operation. Standard APIs allow server to interpret program semantics. Sources: Picture by IBM blog.
  • 7. Where we transition to: greenfield “micro”-services. JAR JAR JAR JAR JAR JAR service A service B service C HTTP/protobuf HTTP/protobuf Sources: Lagom is a Lightbend trademark, Spring Boot is a Pivotal trademark.
  • 8. Where we transition to: “The wheel of doom” Twitter Hailo The Empire Simple bits, complex interaction: death star topologies. Sources: Screenshots from Zipkin on Twitter Blog and Hailo Blog. Death Star by “Free Star Wars Fan Art Collection”.
  • 9. Where we transition to: simple services, complex operation. 1. Writing distributed services can ease development but adds challenges on integration. 2. Distributed services without standardized APIs cannot easily be observed in interaction. 3. Distributed services make it harder to collect structured monitoring data. 4. Distributed (micro-)services require DevOps to successfully run in production. Sources: Picture by Reddit.
  • 10. JAR JAR The next big thing: serverless architecture? JAR JAR JAR JAR dispatcher A dispatcher B dispatcher C Sources: AWS Lambda is an Amazon trademark.
  • 11. The next big thing: serverless architecture? Sources: Picture by Golden Eagle Coin. Concept from: “silver bullet syndrome” by Hadi Hariri. silver bullet syndrome
  • 12. I. Inventory II. Tracing (micro-)services III. Implementing APM IV. Advanced topics Outline
  • 13. trace collector 192.168.0.2/bar.jar – uid(B) 0ms What information do we want? 192.168.0.1/foo.jar 192.168.0.2/bar.jar 192.168.0.3/MySQL HTTP JDBC 77.44.250.1 HTTP uid(A) 192.168.0.1/foo.jar – uid(A) 192.168.0.2 – uid(A) 192.168.0.3/MySQL – uid(B) 100ms 200ms entry exit entry exit uid(A) uid(B) 192.168.0.2/bar.jar – uid(B)uid(A) uid(A)
  • 14. How do we get it? cs sr ss cr span trace 192.168.0.1/foo.jar – uid(A) 192.168.0.3/MySQL – uid(B) 192.168.0.2/bar.jar – uid(B)uid(A) uid(A) { query = select 1 from dual } annotation Source: Logo from zipkin.io.
  • 15. How do we get it? Source: Zipkin screenshot.
  • 16. Span.Builder span = Span.builder() .traceId(42L) .name("foo") .id(48L) .timestamp(System.currentTimeMillis()); long now = System.nanoTime(); // do hard work span = span.duration(System.nanoTime() - now); // send span to server How do we get it? Several competing APIs: 1. Most popular are Zipkin (core) and Brave. 2. Some libraries such as Finagle (RPC) offer built-in Zipkin-compatible tracing. 3. Many plugins exist to add tracing as a drop-in to several libraries. 4. Multiple APIs exist for different non-JVM languages.
  • 17. A standard to the rescue. Source: Logo from opentracing.io. Span span = tracer.buildSpan("foo") .asChildOf(parentSpan.context()) .withTag("bar", "qux") .start(); // do hard work span.finish();
  • 18. A standard to the rescue. Source: “Standards” by xkcd. Problems: 1. Single missing element in chain breaks entire trace. 2. Requires explicit hand-over on every context switch. (Span typically stored in thread-local storage.)
  • 19. I. Inventory II. Tracing (micro-)services III. Implementing APM IV. Advanced topics Outline
  • 20. Drop-in tracing. public class TracingAgent { public static void premain(String arg, Instrumentation inst) { inst.addTransformer( (classLoader, typeName, type, pd, classFile) -> { if (shouldTraceClass(typeName)) { return addTracing(classFile); } else { return null; } }); } private static boolean shouldTraceClass(String typeName) { return false; // TODO: implement } private static byte[] addTracing(byte[] binary) { return binary; // TODO: implement } }
  • 21. High-level instrumentation with Byte Buddy. Code generation and manipulation library: 1. Apache 2.0 licensed. 2. Mature: Over 2 million downloads per year. 3. Requires zero byte-code competence. 4. Safe code generation (no verifier errors). 5. High-performance library (even faster than vanilla-ASM). 6. Already supports Java 9 (experimental). 7. Offers fluent API and type-safe instrumentation. Check out http://bytebuddy.net and https://github.com/raphw/byte-buddy
  • 22. class Foo { String bar() { return "bar"; } } assertThat(new Foo().bar(), is("Hello World!")); public static void premain(String argument, Instrumentation instrumentation) { new AgentBuilder.Default() .type(named("Foo")) .transform( (builder, type, classLoader) -> builder.method(named("bar")) .intercept(value("Hello World!")); ) .installOn(instrumentation); } Java agents with Byte Buddy
  • 23. class ServletAdvice { @OnMethodEnter static void enter(@Argument(0) HttpServletRequest request) { String traceId = request.getHeader("X-Trace-Id"); String method = request.getMethod(); String uri = request.getRequestURI(); if (traceId != null) { ServletTracer.continueTrace(traceId, method, uri); } else { ServletTracer.startTrace(method, uri); } } @OnMethodExit static void exit(@Argument(1) HttpServletResponse response) { ServletTracer.complete(response.getStatusCode()); } } Inlining code with Byte Buddy advice
  • 24. public class ServletTraceAgent { public static void premain(String arg, Instrumentation inst) { new AgentBuilder.Default() .type(isSubTypeOf(Servlet.class)) .transform( (builder, type, classLoader) -> builder.visit(Advice.to(ServletAdvice.class) .on(named("service"))); ).installOn(inst); } } Inlining code with Byte Buddy advice
  • 25. public class ServletTraceAgent { public static void agentmain(String arg, Instrumentation inst) { new AgentBuilder.Default() .disableClassFormatChanges() .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) .type(isSubTypeOf(Servlet.class)) .transform( (builder, type, classLoader) -> builder.visit(Advice.to(ServletAdvice.class) .on(named("service"))); ).installOn(inst); } } Inlining code with Byte Buddy advice
  • 26. APM architecture: example of Instana JARJS JARPHP traces/metrics metrics traces feedback
  • 27. Trace view in Instana (example)
  • 28. Logical view in Instana (example)
  • 29. I. Inventory II. Tracing (micro-)services III. Implementing APM IV. Advanced topics Outline
  • 31. (Adaptive) sampling: events per second (without queue-bound)
  • 32. (Adaptive) sampling: marketing “X% overhead” class MyApp { void foo() { while (true) { handleWebRequest(); } } } class MyOtherApp { void foo() { while (true) { Thread.sleep(100L); } } }
  • 33. JIT-friendly tracing JIT-optimized C CJava incoming outgoing -XX:MaxInlineSize=35 (auto-reduced) -XX:FreqInlineSize=325 -XX:InlineSmallCode=2000 -XX:MaxInlineLevel=9
  • 34. monomorphic bimorphic polymorphic megamorphic direct link vtable lookup (about 90%) Most available tracers know three types of spans: client, server and local. This often leads to “trace call megamorphism” in production systems. optimization deoptimization home of rumors conditional direct link (data structures) (but dominant targets) JIT-friendly tracing: enforcing monomorphism
  • 35. JIT-friendly tracing: copy&paste monomorphism class ServletAdvice { @OnMethodEnter static void enter(@Argument(0) HttpServletRequest request) { String traceId = request.getHeader("X-Trace-Id"); String method = request.getMethod(); String uri = request.getRequestURI(); if (traceId != null) { ServletTracer.continueTrace(traceId, method, uri); } else { ServletTracer.startTrace(method, uri); } } @OnMethodExit static void exit(@Argument(1) HttpServletResponse response) { ServletTracer.complete(response.getStatusCode()); } }
  • 36. Memory-friendly tracing package com.twitter.zipkin.gen; public class Span implements Serializable { public volatile Long startTick; private long trace_id; private String name; private long id; private Long parent_id; private List<Annotation> annotations = emptyList(); private List<BinaryAnnotation> b_annotations = emptyList(); private Boolean debug; private Long timestamp; private Long duration; // ... }
  • 37. Memory-friendly tracing: Zero-garbage tracer Span per event Immutable events Some privitives Linked list attachments Allocation rate correlates with events Vulnerable to false-sharing User-thread centric Scala-style model Span (container) per thread Fully mutable events All primitives (void ids) Raw-data array annotations Allocation rate correlates with sampled events Ensures thread-locality Tracer-thread centric Java-style model
  • 38. Span identification incoming outgoing class MyBatchFramework { void doBatchJob() { // do hard work... } } @com.instana.sdk.Span("trace-me") foo()
  • 39. Context-switch tracing incoming outgoing thread 1 thread 2 Requires explicit context hand-over upon each context-switch.
  • 40. Tracing sandboxed applications class AccessController { public static void checkPermission(Permission permission) throws AccessControlException { AccessControlContext stack = getStackAccessControlContext(); // perform check based on stack } class AccessController { public static void checkPermission(Permission permission) throws AccessControlException { if (isInstanaSandboxed()) { return; } AccessControlContext stack = getStackAccessControlContext(); // perform check based on stack privileges }
  • 41. Testing instrumentation and trace collection JAR main(String[])TestCollector
  • 42. Java 9: challenges ahead of us ClassLoader.getSystemClassLoader() .getResourceAsStream("java/lang/Object.class"); class MyServlet extends MyAbstractServlet class MyAbstractServlet extends Servlet Applies class hierarchy analysis without using reflection API! (Cannot load types during instrumentation. Unless retransforming.) Java 8 Java 9 URL null CHA is also required for inserting stack map frames. Byte Buddy allows for on-the-fly translation of such frames. This way, Bytre Buddy is often faster than vanilla ASM with frame computation enabled. Byte Buddy automatically use loaded type reflection upon retransformation.