SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Profilers Are Lying Hobbitses
Nitsan Wakart (@nitsanw)
Lead Performance Engineer, Azul Systems
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations/
profilers-hotspots-bottlenecks
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
Thanks!
I work on Zing!
● Awesome JVM
● Only on Linux/x86
● Aimed at server side systems
● Highly focused on responsiveness
✔ C4 – Fully concurrent GC
✔ ReadyNow! - Persisted profile data
But Also:
● Blog: http://psy-lob-saw.blogspot.com
● Open Source developer/contributor:
– JCTools
– Aeron/Agrona
– Netty/Akka/RxJava/YCSB/HdrHistogram
– Honest-Profiler/perf-map-agent
● Cape Town Java Meetup Organizer
Why profile?
Also:
https://twitter.com/ITSSADWHEN/status/645557218851557376
Which profiler?
LIVE DEMO TIME!!!!!
Sampling Profilers
● Sample program on interval
● Distribution of samples highlights hotspots
● Assumption: Samples are 'random'
● Assumption: Sample distribution approximates
'Time Spent' distribution
Sampling?
WebServerThread.run()
Controller.doSomething() Controller.next()
Repo.readPerson()
new Person()
View.printHtml()
Sampling Profilers
???
??? ???
Not enough samples
Solution: Switch to tracing profiler
Solution: Shorter sampling interval
Solution: Patience
Sampling interval matching
application life cycle
Solution: Shorter interval
Solution: Randomized interval
Sample taking is expensive
Solution: Switch sampling method
Solution: Accept overhead
Solution: Longer interval
Sample is biased/inaccurate
Solution: Switch sampling method
Solution: Widen your scope
Problems with JVisualVM*?
● Reports all threads (running or not)
● Uses GetStackTrace**:
➢ High overhead
➢ Safepoint** Biased
* And all other JVMTI::GetStackTrace based profilers
** Will be explained shortly…
GetStackTrace: the official API
https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#GetStackTrace
● Input: Thread
● Output:
– Error code (failure IS an option)
– List of frames (jmethodId, jlocation)
jlocation, where J-Lo be at?
BCI → Line of Code
Look in hprof for example: <OPENJDK-HOME>/demo/jvmti/hprof
● BCI – Byte Code Index
● Not every BCI has a line of code
● Find the closest...
GetStackTrace samples at a
Safepoint
Safepoint?
Safepoint (noun.)
A JVM thread state
● Waiting/Idle/Blocked    → @Safepoint
● Running Java code      → !@Safepoint
● Running JNI code       →  @Safepoint
http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html
http://psy-lob-saw.blogspot.com/2014/03/where-is-my-safepoint.html
At a Safepoint
“...the thread's representation of it's Java
machine state is well described, and can
be safely manipulated and observed by
other threads in the JVM”
Gil Tene, on “Mechanical Sympathy” mailing list:
https://groups.google.com/d/msg/mechanical-sympathy/GGByLdAzlPw/cF1_XW
1AbpEJ
Why bring threads to Safepoint?
● Some GC phases
● Deoptimization
● Stack trace dump (and other JVMTI activities)
● Lock un-biasing
● Class redefinition
● And more!
See excellent talks:
https://www.youtube.com/watch?v=Y39kllzX1P8 : “With GC Solved, What Else Makes a JVM Pause?” by John Cutherson
https://vimeo.com/120533011 : “When Does the JVM JIT & Deoptimize?” by Doug Hawkins
How does a JVM bring a
thread to a 'Safepoint'?
1) Raise Safepoint ‘flag’
2) Wait for thread to poll Safepoint 'flag'
3) Thread transitions to Safepoint state
Where do we see a Safepoint
poll?
● Between every 2 bytecodes (interpreter)
● Backedge of non-'counted' loops (C1/C2)
● Method exit (C1/C2)
● JNI call exit
public void foo(Bar bar) {
  int nogCount = 0;
  for (int i = 0; i < 10; i++) {
    if (bar.getZog(i).isNog()) nogCount++; 
  }
  while (nightIsYoung) {
    nogCount += hit(bar);
  }
  if (nogCount > MAX_NOG)
    throw new NogOverflowError();
}
public void foo(Bar bar) {
  int nogCount = 0;
  for (int i = 0; i < 10; i++) {
    if (bar.getZog(i).isNog()) nogCount++; 
  }
  while (nightIsYoung) {
    nogCount += hit(bar);
    // Safepoint poll 
  }
  if (nogCount > MAX_NOG)
    throw new NogOverflowError();
  // Safepoint poll
}
Safepoint Bias
WebServerThread.run()
Controller.doSomething() Controller.next()
Repo.readPerson()
new Person()
View.printHtml() ???
It's just a harmless lil' safepoint they said
GetStackTrace Overheads
setSafepoint(true)
@Safepoint
Actual GetStackTrace work
resumeAll()
PROF J1@J J4@JNIJ2@J J3@J J5@JNI
GetStackTrace overhead
(OpenJDK)
● Stop ALL Java threads
● Collect single/all thread call traces
● Resume ALL stopped threads
Use -XX:+PrintGCApplicationStoppedTime to log pause times
GetStackTrace overhead (Zing)
● Stop sampled Java thread
● Collect single thread call trace
● Resume stopped thread
LIVE DEMO TIME!!!!!
GetStackTrace demo points
● Use -XX:+PrintGCApplicationStoppedTime
● Safepoint location is 'arbitrary'
● Overhead scales with number of threads
● Widen scope up the call tree?
I will not buy this RECORD, it is
SCRATCHED!!!!
AsyncGetCallTrace: unofficial API
● Input: signal context and JNI env
– Context will provide PC/FP/SP
● Output:
– Error code (failure IS an option)
– List of frames (jmethodId, lineno)
– lineno == BCI
Why Use AsyncGetCallTrace?
● Built for sampling in signal handler
● Does not require a safepoint
● Samples the interrupted thread
● Interrupted thread need not be at safepoint
http://jeremymanson.blogspot.co.za/2007/05/profiling-with-jvmtijvmpi-sigprof-and.html
http://jeremymanson.blogspot.co.za/2013/07/lightweight-asynchronous-sampling.html
AsyncGetCallTrace sequence
signal()
OS interrupt
Interrupt Handler
AsyncGetStackTrace
Serialize
TIMER J1@J J4@JNIJ2@J J5@JNI
signal() OS interrupt
Interrupt Handler
AsyncGetStackTrace
Serialize
Who Uses AsyncGetCallTrace?
● Solaris Studio (but not only AGCT...)
● Java Flight Recorder
● Lightweight-Java-Profiler
● Honest-Profiler
LIVE DEMO TIME!!!!!
AGCT demo points
● Use: -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints
● Only Java stack is covered
● Only on CPU is sampled
● Lookout for failed samples
Oh?
You want the truth?
Reality is complex...
● There is no Line Of Code
● There's no BCI
● Only instructions
● And more than just Java
Stack Frame → Call Trace Frame
● Stack frame:
– PC – program counter
– FP – frame pointer (optional)
– SP – stack pointer
● Call trace frame:
– jmethodid
– BCI
PC → BCI
● PC points to the 'current' instruction
● Not every instruction has a BCI
● Find the closest...
Funny Thing About PCs...
“> I think Andi mentioned this to me last year --
> that instruction profiling was no longer reliable.
It never was.”
http://permalink.gmane.org/gmane.linux.kernel.perf.user/1948
Exchange between Brenden Gregg and Andi Kleen
Skid
● Super Scalar CPU
● Speculative execution
● Signal latency
The blamed instruction is often shortly after
where the big cost lies
PC → BCI → Line of Code
● This is as good as it gets
● Mostly it's good enough
● Look for other suspects
nearby
Nearby? Nearby where?
LIVE DEMO TIME!!!!!
Perf-map-agent demo points
● Use: -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints
● No LOC info (fixable)
● Only on CPU is sampled
● Opportunity to differentiate virtual/real frames
WebServerThread.run()
Controller.doSomething() Controller.next()
Repo.readPerson()
new Person()
View.printHtml()
Inlining JIT Compilation
f()
g() h()
???
???
?
?
?
z()
Take Aways
● Know your profiler
● There's no perfect profiler
● Try an 'unbiased' profiler, give honest-
profiler/perf-map-agent a go!
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/profilers-
hotspots-bottlenecks

Weitere ähnliche Inhalte

Mehr von C4Media

Mehr von C4Media (20)

Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Profilers Are Lying Hobbits (and we hate them!)