SlideShare a Scribd company logo
1 of 25
Download to read offline
Web Application
Profiling 101
Yinon Avraham
@yinonavraham
OVERVIEW
Go's standard library comes with built-in tools to
support monitoring and profiling applications.
To enable it in a web application, it needs to register
some built-in HTTP endpoints.
We will now review some of the tools.
AGENDA
Exposing Applicative Information
Profiling CPU, Memory and More
Tracing Application Execution
Summary
EXPOSING
APPLICATIVE INFORMATION
EXPVAR PACKAGE
● Provides information on exposed application
variables
● Predefined variables: command line, memory
statistics
● Supports adding custom variables
● Useful for monitoring a running application
EXPVAR EXAMPLE
GET /debug/vars
{
"cmdline": ["/path/to/myapp"],
"memstats": {
"Alloc": 7891752,
"PauseTotalNs": 316582784,
"NumGC": 670,
...
}
}
EXPVAR HOW-TO
import "expvar" // omitted other required imports
var calls expvar.Int
func main() {
expvar.Publish("hello.calls", &calls)
http.HandleFunc("/hello", ServeHello)
log.Fatal(http.ListenAndServe(":7777", nil))
}
func ServeHello(w http.ResponseWriter, req *http.Request) {
calls.Add(1)
fmt.Fprintf(w, "Hello JFrog!")
}
EXPVAR EXAMPLE
GET /debug/vars
{
"cmdline": ["/path/to/myapp"],
"hello.calls": 4,
"memstats": {
...
}
}
PROFILING
CPU, MEMORY & MORE
NET/HTTP/PPROF PACKAGE
Provides a web page with several built-in profiling
information, including:
● Memory allocations
● Synchronization points (blocks)
● Active goroutines
● Locks (mutex)
PROFILING HOW-TO
Register the pprof endpoints, e.g. implicitly:
import _ "net/http/pprof"
Browse to the pprof web page (by default at):
/debug/pprof
Analyze using the pprof tool, for example:
go tool pprof -http :3000 
http://localhost:7777/debug/pprof/profile
CPU PROFILING
/debug/pprof/profile
● Provides information on "hot" paths
● Call stack sample is taken every 10 ms (default)
● Sums the CPU time every sampled function spends
● Has some performance impact (non-neglectable),
but only on-demand
CPU PROFILE DIAGRAMS
Flame Graph
Call Graph
MEMORY PROFILING (sampling)
/debug/pprof/heap
Memory allocations of live objects
/debug/pprof/allocs
All past memory allocations
● Collected by sampling, based on the GC information
● Helps to identify suspects for GC exhaustion
● Use the pprof tool to analyze
GOROUTINES STACK TRACES
/debug/pprof/goroutine
All current goroutines
/debug/pprof/threadcreate
Led to the creation of new OS threads
/debug/pprof/block
Led to blocking on synchronization primitives (inc. channels)
/debug/pprof/mutex
holders of contended mutexes
CUSTOM PROFILES
● Anyone can add custom defined profiles
● Usually used to track resources and identify leaks
● There are some requirements from the managed
resource - read the runtime/pprof package's GoDoc
CUSTOM PROFILES HOW-TO
import "runtime/pprof"
var myProfile = pprof.NewProfile("my.profile")
func New() *Resource {
r := &Resource{}
myProfile.Add(r, 1)
return r
}
func (r *Resource) Close() {
myProfile.Remove(r)
}
TRACING
APPLICATION EXECUTION
TRACE TOOL
● Used to trace the execution of a running application
● Provides visual information on:
○ Goroutines Scheduling
○ CPU Utilization
○ Heap Memory Allocation
○ GC
TRACE HOW-TO
1. Collect trace information for e.g. 5 seconds:
GET /debug/pprof/trace?seconds=5
And save the output to a file
(e.g. using: curl <url> -o trace.out)
2. Use the trace tool to open a web browser:
go tool trace trace.out
TRACE EXAMPLE
SUMMARY
SUMMARY
● Make the debug endpoints (vars, pprof, etc.)
available at runtime
● Use the expvar package to expose applicative
information and metrics
● DON'T use net/http package's DefaultServeMux,
create your own, explicitly add debug endpoints
● MUST restrict access to the debug endpoints
e.g. put behind auth, or use non-public IP & port
REFERENCES
● Go Tooling in Action (Francesc Campoy)
https://youtu.be/uBjoTxosSys
● Profiling and Optimizing Go (Prashant Varanasi)
https://youtu.be/N3PWzBeLX2M
● Profiling & Optimizing in Go (Brad Fitzpatrick)
https://youtu.be/xxDZuPEgbBU
● Profiling Go programs with pprof (Julia Evans)
https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/
● Profiling a go service in production (Alexander Else)
https://youtu.be/19bxBMPOlyA
● Two Go Programs, Three Different Profiling Techniques (Dave Cheney)
https://youtu.be/nok0aYiGiYA
● Custom pprof profiles (Jaana B. Dogan)
https://rakyll.org/custom-profiles/
THANK
YOU

More Related Content

What's hot

2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins generalRoland Bouman
 
A little systemtap
A little systemtapA little systemtap
A little systemtapyang bingwu
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Alexander Shulgin
 
Gdb basics for my sql db as (openfest 2017) final
Gdb basics for my sql db as (openfest 2017) finalGdb basics for my sql db as (openfest 2017) final
Gdb basics for my sql db as (openfest 2017) finalValeriy Kravchuk
 
Writing and Publishing Puppet Modules
Writing and Publishing Puppet ModulesWriting and Publishing Puppet Modules
Writing and Publishing Puppet ModulesPuppet
 
Pynvme introduction
Pynvme introductionPynvme introduction
Pynvme introductionCrane Chu
 
톰캣 #04-환경설정
톰캣 #04-환경설정톰캣 #04-환경설정
톰캣 #04-환경설정GyuSeok Lee
 
Puppet Camp Ghent 2013
Puppet Camp Ghent 2013Puppet Camp Ghent 2013
Puppet Camp Ghent 2013Server Density
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021Valeriy Kravchuk
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAsGokhan Atil
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingScyllaDB
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programsBadoo Development
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Valerii Kravchuk
 
とにかく始めるClojure
とにかく始めるClojureとにかく始めるClojure
とにかく始めるClojureMasayuki Muto
 
Shellcode injection
Shellcode injectionShellcode injection
Shellcode injectionDhaval Kapil
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPANcharsbar
 
IEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersIEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersRamin Orujov
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevJian-Hong Pan
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealTzung-Bi Shih
 

What's hot (20)

1. MySql plugins
1. MySql plugins1. MySql plugins
1. MySql plugins
 
2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins general
 
A little systemtap
A little systemtapA little systemtap
A little systemtap
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
Gdb basics for my sql db as (openfest 2017) final
Gdb basics for my sql db as (openfest 2017) finalGdb basics for my sql db as (openfest 2017) final
Gdb basics for my sql db as (openfest 2017) final
 
Writing and Publishing Puppet Modules
Writing and Publishing Puppet ModulesWriting and Publishing Puppet Modules
Writing and Publishing Puppet Modules
 
Pynvme introduction
Pynvme introductionPynvme introduction
Pynvme introduction
 
톰캣 #04-환경설정
톰캣 #04-환경설정톰캣 #04-환경설정
톰캣 #04-환경설정
 
Puppet Camp Ghent 2013
Puppet Camp Ghent 2013Puppet Camp Ghent 2013
Puppet Camp Ghent 2013
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAs
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using Tracing
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
 
とにかく始めるClojure
とにかく始めるClojureとにかく始めるClojure
とにかく始めるClojure
 
Shellcode injection
Shellcode injectionShellcode injection
Shellcode injection
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
 
IEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersIEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developers
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
 

Similar to Web Application Profiling 101

[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
Continuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityContinuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityScyllaDB
 
Passenger 6 generic language support presentation
Passenger 6 generic language support presentationPassenger 6 generic language support presentation
Passenger 6 generic language support presentationHongli Lai
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.orgTed Husted
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside OutFerenc Kovács
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Valeriy Kravchuk
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersJavan Rasokat
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Bastian Feder
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...OpenShift Origin
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Amin Astaneh
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfLuca Mattia Ferrari
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and toolszhang hua
 

Similar to Web Application Profiling 101 (20)

[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
Continuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityContinuous Go Profiling & Observability
Continuous Go Profiling & Observability
 
Introduction to Apache Apex
Introduction to Apache ApexIntroduction to Apache Apex
Introduction to Apache Apex
 
Passenger 6 generic language support presentation
Passenger 6 generic language support presentationPassenger 6 generic language support presentation
Passenger 6 generic language support presentation
 
NodeJS
NodeJSNodeJS
NodeJS
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
php & performance
 php & performance php & performance
php & performance
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Cloud Monitoring tool Grafana
Cloud Monitoring  tool Grafana Cloud Monitoring  tool Grafana
Cloud Monitoring tool Grafana
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and tools
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

Web Application Profiling 101

  • 1. Web Application Profiling 101 Yinon Avraham @yinonavraham
  • 2. OVERVIEW Go's standard library comes with built-in tools to support monitoring and profiling applications. To enable it in a web application, it needs to register some built-in HTTP endpoints. We will now review some of the tools.
  • 3. AGENDA Exposing Applicative Information Profiling CPU, Memory and More Tracing Application Execution Summary
  • 5. EXPVAR PACKAGE ● Provides information on exposed application variables ● Predefined variables: command line, memory statistics ● Supports adding custom variables ● Useful for monitoring a running application
  • 6. EXPVAR EXAMPLE GET /debug/vars { "cmdline": ["/path/to/myapp"], "memstats": { "Alloc": 7891752, "PauseTotalNs": 316582784, "NumGC": 670, ... } }
  • 7. EXPVAR HOW-TO import "expvar" // omitted other required imports var calls expvar.Int func main() { expvar.Publish("hello.calls", &calls) http.HandleFunc("/hello", ServeHello) log.Fatal(http.ListenAndServe(":7777", nil)) } func ServeHello(w http.ResponseWriter, req *http.Request) { calls.Add(1) fmt.Fprintf(w, "Hello JFrog!") }
  • 8. EXPVAR EXAMPLE GET /debug/vars { "cmdline": ["/path/to/myapp"], "hello.calls": 4, "memstats": { ... } }
  • 10. NET/HTTP/PPROF PACKAGE Provides a web page with several built-in profiling information, including: ● Memory allocations ● Synchronization points (blocks) ● Active goroutines ● Locks (mutex)
  • 11. PROFILING HOW-TO Register the pprof endpoints, e.g. implicitly: import _ "net/http/pprof" Browse to the pprof web page (by default at): /debug/pprof Analyze using the pprof tool, for example: go tool pprof -http :3000 http://localhost:7777/debug/pprof/profile
  • 12. CPU PROFILING /debug/pprof/profile ● Provides information on "hot" paths ● Call stack sample is taken every 10 ms (default) ● Sums the CPU time every sampled function spends ● Has some performance impact (non-neglectable), but only on-demand
  • 13. CPU PROFILE DIAGRAMS Flame Graph Call Graph
  • 14. MEMORY PROFILING (sampling) /debug/pprof/heap Memory allocations of live objects /debug/pprof/allocs All past memory allocations ● Collected by sampling, based on the GC information ● Helps to identify suspects for GC exhaustion ● Use the pprof tool to analyze
  • 15. GOROUTINES STACK TRACES /debug/pprof/goroutine All current goroutines /debug/pprof/threadcreate Led to the creation of new OS threads /debug/pprof/block Led to blocking on synchronization primitives (inc. channels) /debug/pprof/mutex holders of contended mutexes
  • 16. CUSTOM PROFILES ● Anyone can add custom defined profiles ● Usually used to track resources and identify leaks ● There are some requirements from the managed resource - read the runtime/pprof package's GoDoc
  • 17. CUSTOM PROFILES HOW-TO import "runtime/pprof" var myProfile = pprof.NewProfile("my.profile") func New() *Resource { r := &Resource{} myProfile.Add(r, 1) return r } func (r *Resource) Close() { myProfile.Remove(r) }
  • 19. TRACE TOOL ● Used to trace the execution of a running application ● Provides visual information on: ○ Goroutines Scheduling ○ CPU Utilization ○ Heap Memory Allocation ○ GC
  • 20. TRACE HOW-TO 1. Collect trace information for e.g. 5 seconds: GET /debug/pprof/trace?seconds=5 And save the output to a file (e.g. using: curl <url> -o trace.out) 2. Use the trace tool to open a web browser: go tool trace trace.out
  • 23. SUMMARY ● Make the debug endpoints (vars, pprof, etc.) available at runtime ● Use the expvar package to expose applicative information and metrics ● DON'T use net/http package's DefaultServeMux, create your own, explicitly add debug endpoints ● MUST restrict access to the debug endpoints e.g. put behind auth, or use non-public IP & port
  • 24. REFERENCES ● Go Tooling in Action (Francesc Campoy) https://youtu.be/uBjoTxosSys ● Profiling and Optimizing Go (Prashant Varanasi) https://youtu.be/N3PWzBeLX2M ● Profiling & Optimizing in Go (Brad Fitzpatrick) https://youtu.be/xxDZuPEgbBU ● Profiling Go programs with pprof (Julia Evans) https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/ ● Profiling a go service in production (Alexander Else) https://youtu.be/19bxBMPOlyA ● Two Go Programs, Three Different Profiling Techniques (Dave Cheney) https://youtu.be/nok0aYiGiYA ● Custom pprof profiles (Jaana B. Dogan) https://rakyll.org/custom-profiles/