SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
Python, Go, and the Cost of
Concurrency in the Cloud
• Quick discussion of moving from Python to Go
• Explaining key differences between Go and other “no
semicolons” languages
• Show an example application illustrating why those key
differences matter for your app’s bottom line
Goal of this talk
• Daily Python hacker
• Came from C/C++, UNIX systems hacking background
• PhD on P2P/crypto research, more C++ & Python
• Six months experience in Go
• Co-founder, Tracelytics; Chief Architect, AppNeta
About me
Chris Erway, AppNeta Chief Architect
• Fun to program — “Zen of Python”
• Built-in maps, sets, arrays, tuples
• Good library support
• Simple duck typing (as opposed to strict OO)
• A little code goes a long way
Things I like about Python
• Performance: not too slow, but not too fast either
• Dependencies can be a pain (virtualenv, pip, etc)
• The dreaded Global Interpreter Lock (GIL)
• Lack of typed function signatures can make reading code
difficult
Things I don’t like about Python
• Announced 2009
• Creators: Ken Thompson (B, Plan 9 from Bell Labs), Rob Pike
(Plan 9), Robert Griesemer (V8 engine)
• “all three of us had to be talked into every feature in the
language, so there was no extraneous garbage put into the
language for any reason”
• Statically typed, garbage-collected
• Fast compilation, static linking
Go
• Easy to read, no semicolons
• Built-in maps, arrays, strings
• Both support calling into C code when necessary
• Interfaces based on duck typing
• No virtual inheritance
• Statically typed, but automatic type inference and interfaces
give it a “dynamic feel”
Similarities between Go and Python
• Go is compiled to native machine code
• Fast compiler, single static binary
• Go is fast; memory usage depends on size of structs
• No per-object dictionaries, as in Python
• Go has concurrency features built into the language: goroutines,
channels, runtime scheduler
• Go has curly braces
Differences between Go and Python
Language comparison
• Lots of resources online for learning Go!
• Following 4 slides from “Go for Pythonistas” by Francesc
Campoy Flores, Google
• See also: The Go Programming Language Blog, blog.golang.org
For more on Go ...
• Goroutines: very light processing actors (the gophers)
• Channels: typed, synchronized, thread-safe pipes (the arrows)
Go concurrency
Based on goroutines and channels
Fibonacci with Python generators
“Generator” goroutines
A function that returns a channel:
Concurrency across languages
(From Brad Fitzpatrick’s Gocon Tokyo 2014 talk)
So who cares?
You do!
• You do — concurrency is very important in the modern
computing environment
• Programming for “the cloud” or for “SOA” or “microservices” is
fundamentally different than writing a LAMP/MEAN/Rails app
• Assumptions on latency, throughput, scale all change
• The language you pick can cost you time & money
Modern systems demand concurrency
• Pre-cloud systems and databases generally use pools of long-
living, low-latency connections
• Cloud & SOA/microservices often rely on HTTPS-based APIs
• “Infinite” scale, but with more latency
• For example: Amazon SQS vs RabbitMQ
• HTTP-based APIs have inherently higher latencies
• Amazon DynamoDB 5-10ms latency
• Amazon Kinesis PutRecords, S3, SQS 10-100ms latency
• Usage-based pricing
• Higher throughput = more concurrent HTTP connections
What about my async code for Python,
Ruby, Node?
• Async I/O makes network, disk reads & writes asynchronous
• Used by Python’s gevent, Tornado, Twisted
• Ruby EventMachine, Celluloid
• However Python, Ruby, Node.js
all still use a single-threaded
interpreter
• Interpreter can switch to another execution
context/greenlet/thread while I/O is pending
• Go: thousands of goroutines are mapped to all available cores
Cloud APIs require compute-heavy RPCs
• HTTP-based APIs with authenticated JSON/XML
• Encryption: TLS/SSL key exchange, negotiation
• Authentication: AWS, Google request signature schemes
• Serialization: Convert data to JSON, base64, etc
• Not as simple as binary data over raw sockets
• Not pure disk/network I/O — not as easy to use async I/O
Increasing prevalence of multi-core
architectures
• Quad-core, 8-core, 16-core, 20-core, 32-core, 40-core …
• How will you use all those CPUs?
• Strong opinion: Docker, containerization sometimes
used as a crutch for horizontally scaling services written
in single-threaded languages
Motivating example
• ~1000 items analyzed each second
• ~1000 Amazon S3 PUTs/sec, ~70KB each
• ~1000 Amazon DynamoDB item writes/sec
Cloud storage, queue, and log costs
Motivating example
• ~1000 items analyzed each second
• ~1000 Amazon S3 PUTs/sec, ~70KB each
• ~1000 Amazon DynamoDB item writes/sec
Why not queue the writes for later?
• ~1000 items analyzed each second
• ~1000 Amazon S3 PUTs/sec, ~70KB each
• ~1000 Amazon DynamoDB item writes/sec
Batch writes for fewer PUTs
• Read data objects from Amazon SQS
• Batch into larger files and store in Amazon S3
Baseline: Amazon SQS + S3 + DynamoDB
No batching
Amazon SQS + S3 + DynamoDB
BATCH_SZ=10
Amazon SQS + S3 + DynamoDB
BATCH_SZ=100
Amazon SQS + S3 + DynamoDB
BATCH_SZ=1000
Basic algorithm
Implementation difficulties
Single Python processes
~50 messages/sec
Multiple Python processes
4 procs = ~200 messages/sec
Process-based scaling leads to
suboptimal cost performance
• Impossible to scale number of
Amazon SQS pollers and S3 writers
independently
• One batch buffers per process:
smaller batches than optimal, hard
to “max out” S3 batch size before
timeout
• Hard to “max out” 10 messages each
SQS read
• Hard to detect when system is falling
behind, problematic if write latency >
read latency
Go implementation
Concurrency costs money
• The concurrency model your language provides is very important
when your code combines lots of high-latency API calls / RPCs
• Ruby, Python, Node.js all require lots of concurrent processes to
achieve good concurrency
• Result: over-provisioning, over-polling, IPC when you don’t need to
• Result: suboptimal cost when using usage-priced APIs
Couldn’t I just use {C, C++, Java, Scala,
Clojure, Erlang, Haskell} for concurrency?
• Yes, but —
• it may still be such a pain to spawn & use threads in your
language that you don’t do it enough (e.g. in Java, C/C++ vs.
just typing “go func()”)
• Lock-based synchronized memory access more
complicated than channels
• C/C++ and Java have pretty heavyweight thread sizes, typically
can only support 1K-10K threads
• Go (and Erlang) have very lightweight threads and can support
millions of goroutines
Does this apply to me?
• Increasingly, yes
• More cores, more cloud, all the time
• SOA, “microservices”
• Do you have code that calls multiple independent services
serially?
• Why?
Thank you!
• Hope this was useful and interesting!
• Win a BB-8 droid at our booth #131!
• Next drawing is at 3:15PM today
• AppNeta is hiring! Engineering roles in Providence, Boston,
Vancouver
• http://www.appneta.com/about/careers/
Backup slides (if potential Q&A question comes up)
Amazon Kinesis + S3 + DynamoDB
Provisioned throughput per shard + PUT units
RabbitMQ + Amazon S3 + DynamoDB
self-managed queue instances

Más contenido relacionado

Último

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
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, ...apidays
 
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 WorkerThousandEyes
 
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 TerraformAndrey Devyatkin
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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 businesspanagenda
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
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...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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 FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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 educationjfdjdjcjdnsjd
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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, ...
 
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
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Python, Go, and the Cost of Concurrency in the Cloud | AWS re:Invent

  • 1. Python, Go, and the Cost of Concurrency in the Cloud
  • 2. • Quick discussion of moving from Python to Go • Explaining key differences between Go and other “no semicolons” languages • Show an example application illustrating why those key differences matter for your app’s bottom line Goal of this talk
  • 3. • Daily Python hacker • Came from C/C++, UNIX systems hacking background • PhD on P2P/crypto research, more C++ & Python • Six months experience in Go • Co-founder, Tracelytics; Chief Architect, AppNeta About me Chris Erway, AppNeta Chief Architect
  • 4. • Fun to program — “Zen of Python” • Built-in maps, sets, arrays, tuples • Good library support • Simple duck typing (as opposed to strict OO) • A little code goes a long way Things I like about Python
  • 5. • Performance: not too slow, but not too fast either • Dependencies can be a pain (virtualenv, pip, etc) • The dreaded Global Interpreter Lock (GIL) • Lack of typed function signatures can make reading code difficult Things I don’t like about Python
  • 6. • Announced 2009 • Creators: Ken Thompson (B, Plan 9 from Bell Labs), Rob Pike (Plan 9), Robert Griesemer (V8 engine) • “all three of us had to be talked into every feature in the language, so there was no extraneous garbage put into the language for any reason” • Statically typed, garbage-collected • Fast compilation, static linking Go
  • 7. • Easy to read, no semicolons • Built-in maps, arrays, strings • Both support calling into C code when necessary • Interfaces based on duck typing • No virtual inheritance • Statically typed, but automatic type inference and interfaces give it a “dynamic feel” Similarities between Go and Python
  • 8. • Go is compiled to native machine code • Fast compiler, single static binary • Go is fast; memory usage depends on size of structs • No per-object dictionaries, as in Python • Go has concurrency features built into the language: goroutines, channels, runtime scheduler • Go has curly braces Differences between Go and Python
  • 10. • Lots of resources online for learning Go! • Following 4 slides from “Go for Pythonistas” by Francesc Campoy Flores, Google • See also: The Go Programming Language Blog, blog.golang.org For more on Go ...
  • 11. • Goroutines: very light processing actors (the gophers) • Channels: typed, synchronized, thread-safe pipes (the arrows) Go concurrency Based on goroutines and channels
  • 12. Fibonacci with Python generators
  • 13. “Generator” goroutines A function that returns a channel:
  • 14. Concurrency across languages (From Brad Fitzpatrick’s Gocon Tokyo 2014 talk)
  • 15. So who cares? You do! • You do — concurrency is very important in the modern computing environment • Programming for “the cloud” or for “SOA” or “microservices” is fundamentally different than writing a LAMP/MEAN/Rails app • Assumptions on latency, throughput, scale all change • The language you pick can cost you time & money
  • 16. Modern systems demand concurrency • Pre-cloud systems and databases generally use pools of long- living, low-latency connections • Cloud & SOA/microservices often rely on HTTPS-based APIs • “Infinite” scale, but with more latency • For example: Amazon SQS vs RabbitMQ • HTTP-based APIs have inherently higher latencies • Amazon DynamoDB 5-10ms latency • Amazon Kinesis PutRecords, S3, SQS 10-100ms latency • Usage-based pricing • Higher throughput = more concurrent HTTP connections
  • 17. What about my async code for Python, Ruby, Node? • Async I/O makes network, disk reads & writes asynchronous • Used by Python’s gevent, Tornado, Twisted • Ruby EventMachine, Celluloid • However Python, Ruby, Node.js all still use a single-threaded interpreter • Interpreter can switch to another execution context/greenlet/thread while I/O is pending • Go: thousands of goroutines are mapped to all available cores
  • 18. Cloud APIs require compute-heavy RPCs • HTTP-based APIs with authenticated JSON/XML • Encryption: TLS/SSL key exchange, negotiation • Authentication: AWS, Google request signature schemes • Serialization: Convert data to JSON, base64, etc • Not as simple as binary data over raw sockets • Not pure disk/network I/O — not as easy to use async I/O
  • 19. Increasing prevalence of multi-core architectures • Quad-core, 8-core, 16-core, 20-core, 32-core, 40-core … • How will you use all those CPUs? • Strong opinion: Docker, containerization sometimes used as a crutch for horizontally scaling services written in single-threaded languages
  • 20. Motivating example • ~1000 items analyzed each second • ~1000 Amazon S3 PUTs/sec, ~70KB each • ~1000 Amazon DynamoDB item writes/sec
  • 21. Cloud storage, queue, and log costs
  • 22. Motivating example • ~1000 items analyzed each second • ~1000 Amazon S3 PUTs/sec, ~70KB each • ~1000 Amazon DynamoDB item writes/sec
  • 23. Why not queue the writes for later? • ~1000 items analyzed each second • ~1000 Amazon S3 PUTs/sec, ~70KB each • ~1000 Amazon DynamoDB item writes/sec
  • 24. Batch writes for fewer PUTs • Read data objects from Amazon SQS • Batch into larger files and store in Amazon S3
  • 25. Baseline: Amazon SQS + S3 + DynamoDB No batching
  • 26. Amazon SQS + S3 + DynamoDB BATCH_SZ=10
  • 27. Amazon SQS + S3 + DynamoDB BATCH_SZ=100
  • 28. Amazon SQS + S3 + DynamoDB BATCH_SZ=1000
  • 32. Multiple Python processes 4 procs = ~200 messages/sec
  • 33. Process-based scaling leads to suboptimal cost performance • Impossible to scale number of Amazon SQS pollers and S3 writers independently • One batch buffers per process: smaller batches than optimal, hard to “max out” S3 batch size before timeout • Hard to “max out” 10 messages each SQS read • Hard to detect when system is falling behind, problematic if write latency > read latency
  • 35. Concurrency costs money • The concurrency model your language provides is very important when your code combines lots of high-latency API calls / RPCs • Ruby, Python, Node.js all require lots of concurrent processes to achieve good concurrency • Result: over-provisioning, over-polling, IPC when you don’t need to • Result: suboptimal cost when using usage-priced APIs
  • 36. Couldn’t I just use {C, C++, Java, Scala, Clojure, Erlang, Haskell} for concurrency? • Yes, but — • it may still be such a pain to spawn & use threads in your language that you don’t do it enough (e.g. in Java, C/C++ vs. just typing “go func()”) • Lock-based synchronized memory access more complicated than channels • C/C++ and Java have pretty heavyweight thread sizes, typically can only support 1K-10K threads • Go (and Erlang) have very lightweight threads and can support millions of goroutines
  • 37. Does this apply to me? • Increasingly, yes • More cores, more cloud, all the time • SOA, “microservices” • Do you have code that calls multiple independent services serially? • Why?
  • 38. Thank you! • Hope this was useful and interesting! • Win a BB-8 droid at our booth #131! • Next drawing is at 3:15PM today • AppNeta is hiring! Engineering roles in Providence, Boston, Vancouver • http://www.appneta.com/about/careers/
  • 39. Backup slides (if potential Q&A question comes up)
  • 40. Amazon Kinesis + S3 + DynamoDB Provisioned throughput per shard + PUT units
  • 41. RabbitMQ + Amazon S3 + DynamoDB self-managed queue instances