SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Why my Go 
program is slow? 
GoCon 2014 autumn, INADA Naoki
INADA Naoki 
• @methane 
• KLab Inc. 
• Python 
• mysqlclient, PyMySQL, msgpack
And I’m gopher 
• I love Go. It’s more Pythonic than Python! 
• Explicit is better than implicit. 
• Simple is better than complex. 
• Readability counts. 
• There should be one-- and preferably only 
one --obvious way to do it. 
• Although that way may not be obvious at 
first unless you're Dutch (Gopher).
Today 
• CPU profiling with pprof 
• Random notes about Go’s performance. 
• What I hope Go 1.5~ will have
CPU profiling with 
pprof
runtime/pprof 
• Sampling profiler. 
• net/http/pprof provides HTTP API for 
pprof 
• github.com/davecheney/profile provice 
easy API for CLI program.
NOTE for Mac 
• Go’s CPU profiling is not work on Mac 
• Russ Cox (rsc) explains why: 
http://research.swtch.com/macpprof 
• And he provides kernel patch: 
http://godoc.org/code.google.com/p/rsc/ 
cmd/pprof_mac_fix 
• Activity monitor or Instruments provides 
another sampling profiler
pprof command 
• Included in google perftools 
• ~Go 1.3 bundles CLI (perl) 
• Go 1.4 has reimplement it with Go!
Embed net/http/pprof 
import ( 
“net/http” 
_ “net/http/pprof” 
) 
func main() { 
go http.ListenAndServe(“:5000”, nil) 
}
Let’s use it 
• top 
• web (svg) 
• list, disasm, and weblist
Random notes 
about Go’s performance
Things makes Go slower 
• GC 
• memcpy 
• function call
GC 
• GODEBUG=gctrace=1 
• heap profile with pprof 
• sync.Pool 
• Provide size hint for slice and map. 
• make([]int, 0, hint) 
• make(map[int]int, hint) 
• GOGC=400
memcpy 
• Choose carefully string or []byte 
• Especially for constants
function call 
• Go’s calling convention is much slower than C. 
• No pass by register 
• All register are volatile 
• hook for runtime. 
• But Go has inlining 
• small leaf function may be inlined 
• Not inlined func may not have hook, too.
compare 
• calls1.go 
http://play.golang.org/p/N8oz-eyFII 
• calls2.go 
http://play.golang.org/p/s_Uv0vWirZ 
13022001ns vs 10698225ns
What I hope Go 1.5~ will 
have 
• Concurrent GC will be come in Go 1.5! 
• But more speed is welcome anytime 
• fastcall for leaf function? 
• pass by register 
• volatile register

Weitere ähnliche Inhalte

Was ist angesagt?

Mono + .NET Core = ❤️
Mono + .NET Core =  ❤️Mono + .NET Core =  ❤️
Mono + .NET Core = ❤️
Egor Bogatov
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 

Was ist angesagt? (20)

CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
Mono + .NET Core = ❤️
Mono + .NET Core =  ❤️Mono + .NET Core =  ❤️
Mono + .NET Core = ❤️
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
 
Modern C++
Modern C++Modern C++
Modern C++
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
C++totural file
C++totural fileC++totural file
C++totural file
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
What's new in c#7
What's new in c#7What's new in c#7
What's new in c#7
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
Go之道
Go之道Go之道
Go之道
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
 

Andere mochten auch

PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
Inada Naoki
 
Serverspec at July Tech Festa 2013
Serverspec at July Tech Festa 2013Serverspec at July Tech Festa 2013
Serverspec at July Tech Festa 2013
Gosuke Miyashita
 

Andere mochten auch (20)

NSQ-Centric Architecture (GoCon Autumn 2014)
NSQ-Centric Architecture (GoCon Autumn 2014)NSQ-Centric Architecture (GoCon Autumn 2014)
NSQ-Centric Architecture (GoCon Autumn 2014)
 
PHP7を魔改造した話
PHP7を魔改造した話PHP7を魔改造した話
PHP7を魔改造した話
 
20110224 flamixer
20110224 flamixer20110224 flamixer
20110224 flamixer
 
Nsq.io on Node.js and Shell
Nsq.io on Node.js and ShellNsq.io on Node.js and Shell
Nsq.io on Node.js and Shell
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 
JVM! JVM! JVM!
JVM! JVM! JVM!JVM! JVM! JVM!
JVM! JVM! JVM!
 
Pyfes201110
Pyfes201110Pyfes201110
Pyfes201110
 
Serverspec at July Tech Festa 2013
Serverspec at July Tech Festa 2013Serverspec at July Tech Festa 2013
Serverspec at July Tech Festa 2013
 
Nsq meetup-messaging
Nsq meetup-messagingNsq meetup-messaging
Nsq meetup-messaging
 
Walter ファミリーの紹介 at Shibuya.go#1
Walter ファミリーの紹介 at Shibuya.go#1Walter ファミリーの紹介 at Shibuya.go#1
Walter ファミリーの紹介 at Shibuya.go#1
 
Goroutineと channelから はじめるgo言語
Goroutineと channelから はじめるgo言語Goroutineと channelから はじめるgo言語
Goroutineと channelから はじめるgo言語
 
Float is Legacy
Float is LegacyFloat is Legacy
Float is Legacy
 
Serverspec at Testing Framework Meeting
Serverspec at Testing Framework MeetingServerspec at Testing Framework Meeting
Serverspec at Testing Framework Meeting
 
Presto changes
Presto changesPresto changes
Presto changes
 
Introduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecIntroduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpec
 
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作るGoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
 
Fluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes MeetupFluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes Meetup
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Django
 
ジョジョの奇妙なTDD
ジョジョの奇妙なTDDジョジョの奇妙なTDD
ジョジョの奇妙なTDD
 
How To Write Middleware In Ruby
How To Write Middleware In RubyHow To Write Middleware In Ruby
How To Write Middleware In Ruby
 

Ähnlich wie Why my Go program is slow?

Python to go
Python to goPython to go
Python to go
Weng Wei
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014
Mandi Walls
 

Ähnlich wie Why my Go program is slow? (20)

Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
PWL: One VM to Rule Them All
PWL: One VM to Rule Them AllPWL: One VM to Rule Them All
PWL: One VM to Rule Them All
 
Python to go
Python to goPython to go
Python to go
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
 
Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)
 
How I become Go GDE
How I become Go GDEHow I become Go GDE
How I become Go GDE
 
Erlang: TL;DR
Erlang: TL;DRErlang: TL;DR
Erlang: TL;DR
 
Python VS GO
Python VS GOPython VS GO
Python VS GO
 
Don’t turn your logs into cuneiform
Don’t turn your logs into cuneiformDon’t turn your logs into cuneiform
Don’t turn your logs into cuneiform
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
Go. why it goes v2
Go. why it goes v2Go. why it goes v2
Go. why it goes v2
 
Hands-on go profiling
Hands-on go profilingHands-on go profiling
Hands-on go profiling
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Implementing a command line client to GitHub in Go
Implementing a command line client to GitHub in GoImplementing a command line client to GitHub in Go
Implementing a command line client to GitHub in Go
 
Debugging PySpark - Spark Summit East 2017
Debugging PySpark - Spark Summit East 2017Debugging PySpark - Spark Summit East 2017
Debugging PySpark - Spark Summit East 2017
 
Debugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden KarauDebugging PySpark: Spark Summit East talk by Holden Karau
Debugging PySpark: Spark Summit East talk by Holden Karau
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014
 
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 GolangCOSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
 

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
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...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Why my Go program is slow?

  • 1. Why my Go program is slow? GoCon 2014 autumn, INADA Naoki
  • 2. INADA Naoki • @methane • KLab Inc. • Python • mysqlclient, PyMySQL, msgpack
  • 3. And I’m gopher • I love Go. It’s more Pythonic than Python! • Explicit is better than implicit. • Simple is better than complex. • Readability counts. • There should be one-- and preferably only one --obvious way to do it. • Although that way may not be obvious at first unless you're Dutch (Gopher).
  • 4. Today • CPU profiling with pprof • Random notes about Go’s performance. • What I hope Go 1.5~ will have
  • 6. runtime/pprof • Sampling profiler. • net/http/pprof provides HTTP API for pprof • github.com/davecheney/profile provice easy API for CLI program.
  • 7. NOTE for Mac • Go’s CPU profiling is not work on Mac • Russ Cox (rsc) explains why: http://research.swtch.com/macpprof • And he provides kernel patch: http://godoc.org/code.google.com/p/rsc/ cmd/pprof_mac_fix • Activity monitor or Instruments provides another sampling profiler
  • 8. pprof command • Included in google perftools • ~Go 1.3 bundles CLI (perl) • Go 1.4 has reimplement it with Go!
  • 9. Embed net/http/pprof import ( “net/http” _ “net/http/pprof” ) func main() { go http.ListenAndServe(“:5000”, nil) }
  • 10. Let’s use it • top • web (svg) • list, disasm, and weblist
  • 11. Random notes about Go’s performance
  • 12. Things makes Go slower • GC • memcpy • function call
  • 13. GC • GODEBUG=gctrace=1 • heap profile with pprof • sync.Pool • Provide size hint for slice and map. • make([]int, 0, hint) • make(map[int]int, hint) • GOGC=400
  • 14. memcpy • Choose carefully string or []byte • Especially for constants
  • 15. function call • Go’s calling convention is much slower than C. • No pass by register • All register are volatile • hook for runtime. • But Go has inlining • small leaf function may be inlined • Not inlined func may not have hook, too.
  • 16. compare • calls1.go http://play.golang.org/p/N8oz-eyFII • calls2.go http://play.golang.org/p/s_Uv0vWirZ 13022001ns vs 10698225ns
  • 17. What I hope Go 1.5~ will have • Concurrent GC will be come in Go 1.5! • But more speed is welcome anytime • fastcall for leaf function? • pass by register • volatile register