SlideShare una empresa de Scribd logo
1 de 50
Descargar para leer sin conexión
Why I switch from
python to Go?
weng.wei@zalora.com
About Myself
•

Coding python since 2006

•

Speaker @ PyCon China 2013

•

Architect @ zalora.com

•

https://github.com/Wuvist
!

•

Switching to Go last year
“Switching”
•

Before:
•
•

•

Love Python
python for all projects

After:
•

Still love python

•

python for hobby projects

•

go for serious projects
“Serious Projects”
•

Performance is critical

•

Code Quality is important
!

•

OK, mostly web projects
Performance
•

http://www.techempower.com/benchmarks/
Do you use pypy?
“benchmark could be very misleading”
Stress test on real Go API
Requests/sec:
Transfer/sec:

18071.20
1.19GB
•

Just anything

•

Can python?

•

Can nginx?
Why Go is so fast?
•

Async

•

Compiled

•

Multi-cores
Python
tornado

tornado

tornado

nginx (4 workers)

tornado
nginx <-> tornado
•

Inter-process communication is slow
•
•

memory copy

•
•

network latency

parsing

Process overhead
Python
memcached

tornado

tornado

tornado

nginx (4 workers)

tornado
Go

Go binary with GroupCache

https://github.com/golang/groupcache
Performance

•

Care abut performance? You must consider go

•

http://blog.cloudflare.com/go-at-cloudflare
Code Quality
Error
•

Python: scripting language
•

•

deal with run-time errors

Go: compiled language
•

deal with compile-time errors
Exception Handling

https://twitter.com/yinwang0/status/417899535344472065
Python
•

All exception checked?

•

Which one will crash the process?
!

•

Dunno?
•

Service running in “unknown state” is the worse
thing could happen on production server!
Exception in Go
•

error
•

•

Must check

panic
•

Crash
Hacky

•

Go doesn’t enforce error checking

•

Go enforce all variable usage
➜ ~GOPATH git:(feature/rpccache) ✗ go run h.go
# command-line-arguments
./h.go:8: err declared and not used
Test
•

Python
•

•

Are you actually using pyunit?

Go
•

go test
https://github.com/Wuvist/gophpserialize
https://github.com/Wuvist/gophpserialize/blob/master/
gophpserialize_test.go
➜ gophpserialize git:(master) go test -v
=== RUN TestUnmarshal
--- PASS: TestUnmarshal (0.00 seconds)
=== RUN TestPhpToJson
--- PASS: TestPhpToJson (0.00 seconds)
=== RUN TestPhpToJson2
--- PASS: TestPhpToJson2 (0.00 seconds)
=== RUN TestPhpToJsonComplex
--- PASS: TestPhpToJsonComplex (0.00 seconds)
PASS
ok
_/Users/wuvist/source/gophpserialize 0.021s
Performance Tuning
•

Python:
•

from timeit import Timer ?!

•

import cProfile ?
Go pprof

•

http://blog.golang.org/profiling-go-programs
Productivity
•

go is just like python
•
•

•

easy
concise

Yes, go needs more code than python
•

•

Usually exception checking

Don’t really need to trade productivity for
performance & code quality
Dependency Management
Python


•















•

pip install MySQL-python
•

may work, if you have the prerequisites

•

prerequisites are system wide

•

MySQL-python is system wide

•

So, vitualenv?
go
•

go get = pip (kind of)

•

gopath = per project virtualenv
!

•

Both are built-in tools
Deployment
•

Deploy python(Django?) project
•

WSGI, FastCGI, SCGI, or AJP?

•

python version?

•

dependencies?
GO

•

Copy & run the binary
Concurrency
•

Python
•

twisted

•

gevent

•

not as node.js’s callback hell, but…
Tornado
@gen.coroutine!
def fetch_json(url):!
response = yield AsyncHTTPClient().fetch(url)!
raise gen.Return(json_decode(response.body))!

http://www.tornadoweb.org/en/stable/
gen.html#tornado.gen.coroutine
gevent

>>> from gevent import monkey; monkey.patch_socket()!
>>> import urllib2 # it's usable from multiple greenlets now

http://www.gevent.org/intro.html#monkey-patching
•

How about MySQL-python/pylibmc?

•

Do you really want monkey patch?
•

•

Explicit is better than implicit. - Zen of python?

Or wait for python 3.4?
•

beta 3, 26 January 2014
why not just go?
Q&A
Go tips
•

Start with Go's official libs

•

Look through their source code

•

Consider use/create a framework
•

http://beego.me
cool projects
!

•

GroupCache

•

Docker

•

raft

•

beego
Gotcha
•

Template support is poor

•

Coding with static Type could be tedious
•
•

•

No generic type
reflection is awful

JSON (parsing) is slow! Much slow than python
•

•

https://code.google.com/p/go/issues/detail?id=5683

Only fields with capital letters are exported

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Bitbucket
BitbucketBitbucket
Bitbucket
 
Introduzione a Git
Introduzione a GitIntroduzione a Git
Introduzione a Git
 
Designing a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd productsDesigning a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd products
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
Clean architectures with fast api pycones
Clean architectures with fast api   pyconesClean architectures with fast api   pycones
Clean architectures with fast api pycones
 
Argo Workflows 3.0, a detailed look at what’s new from the Argo Team
Argo Workflows 3.0, a detailed look at what’s new from the Argo TeamArgo Workflows 3.0, a detailed look at what’s new from the Argo Team
Argo Workflows 3.0, a detailed look at what’s new from the Argo Team
 
Learning git
Learning gitLearning git
Learning git
 
Domain Driven Design com Python
Domain Driven Design com PythonDomain Driven Design com Python
Domain Driven Design com Python
 
Golang getting started
Golang getting startedGolang getting started
Golang getting started
 
BitBucket presentation
BitBucket presentationBitBucket presentation
BitBucket presentation
 
Python Worst Practices
Python Worst PracticesPython Worst Practices
Python Worst Practices
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
 
KONG-APIGateway.pptx
KONG-APIGateway.pptxKONG-APIGateway.pptx
KONG-APIGateway.pptx
 
Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1
 
Git basic
Git basicGit basic
Git basic
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 

Similar a Python to go

Progressive Enhancement using WSGI
Progressive Enhancement using WSGIProgressive Enhancement using WSGI
Progressive Enhancement using WSGI
Matthew Wilkes
 
Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014) Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014)
Edem Kumodzi
 

Similar a Python to go (20)

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
 
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
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
Ci of js and apex using jasmine, phantom js and drone io df14
Ci of js and apex using jasmine, phantom js and drone io   df14Ci of js and apex using jasmine, phantom js and drone io   df14
Ci of js and apex using jasmine, phantom js and drone io df14
 
How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015
 
Progressive Enhancement using WSGI
Progressive Enhancement using WSGIProgressive Enhancement using WSGI
Progressive Enhancement using WSGI
 
Testing API's: Tools & Tips & Tricks (Oh My!)
Testing API's: Tools & Tips & Tricks (Oh My!)Testing API's: Tools & Tips & Tricks (Oh My!)
Testing API's: Tools & Tips & Tricks (Oh My!)
 
Making Wallstreet talk with GO (GO India Conference 2015)
Making Wallstreet talk with GO (GO India Conference 2015)Making Wallstreet talk with GO (GO India Conference 2015)
Making Wallstreet talk with GO (GO India Conference 2015)
 
How I become Go GDE
How I become Go GDEHow I become Go GDE
How I become Go GDE
 
Django getting start
Django getting startDjango getting start
Django getting start
 
Why you should use Django in your next project.
Why you should use Django in your next project.Why you should use Django in your next project.
Why you should use Django in your next project.
 
Automated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchAutomated Acceptance Testing from Scratch
Automated Acceptance Testing from Scratch
 
How to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django VersionHow to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django Version
 
Django Dev Environment Howto
Django Dev Environment HowtoDjango Dev Environment Howto
Django Dev Environment Howto
 
Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014) Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014)
 
Building the Pipeline of My Dreams
Building the Pipeline of My DreamsBuilding the Pipeline of My Dreams
Building the Pipeline of My Dreams
 

Más de Weng Wei (13)

Migrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to GoMigrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to Go
 
About Caching
About CachingAbout Caching
About Caching
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
 
谈谈缓存
谈谈缓存谈谈缓存
谈谈缓存
 
用PY实现"Go元编程"
用PY实现"Go元编程"用PY实现"Go元编程"
用PY实现"Go元编程"
 
Go for web
Go for webGo for web
Go for web
 
Go for web
Go for webGo for web
Go for web
 
论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性论使用Python开发推荐引擎的优越性
论使用Python开发推荐引擎的优越性
 
Zalora php to_go
Zalora php to_goZalora php to_go
Zalora php to_go
 
A byte of git
A byte of gitA byte of git
A byte of git
 
My understanding of Git
My understanding of GitMy understanding of Git
My understanding of Git
 
Sharding
ShardingSharding
Sharding
 
Inside Zend Framework
Inside Zend FrameworkInside Zend Framework
Inside Zend Framework
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

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...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
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...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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?
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Python to go