SlideShare a Scribd company logo
The 1990s Called. They Want Their
Code Back.
5 Ways Your Code is Stuck in the 90s
3 Mar 2015
Jonathan Oliver
$ whoami
@jonathan_oliver
http://jonathanoliver.com
http://github.com/joliver
http://keybase.com/joliver
Distributed Podcast
Chief SmartyPants, SmartyStreets
Overview
Disclaimers
Why Go Exists
#1 Implicit messaging
#2 Complex Threading
#3 RPC Everywhere
#4 GC
#5 Logging
Conclusion
Caveats: But, but, but...
Your mileage may vary
Don't apply blindly or wholesale
Sharp knife
Our experience
C# on Windows vs Go on Linux (512 req/s)
hdrhistogram.org
C# Windows vs Golang Linux at 4096 req/s
hdrhistogram.org
C# Windows vs Golang Linux at 8192 req/s
hdrhistogram.org
Why Go Exists
(The real reason)
Compile times?
Multi-core, networked systems
1990ism #1: Implicit Messaging
Hint Dropping Fallacy
If you have to ask, it doesn't mean as much
If you really loved me, you'd know
Implicit Messaging: PHP
<?php
$sql = 'UPDATE Users SET ' +
'firstname = ' $_GET['firstname'] + ','+
'lastname = ' $_GET['lastname'] + ','+
'phone = ' $_GET['phone'] + ','+
'password = ' hash($_GET['password']) + ','+
'WHERE id=' + $_GET['id'];
mysql_query($sql, $connection) or die("Couldn't execute query.");
?>
Implicit Messaging: Go
Where does HTTP stop and the application start?
func implicit(response http.ResponseWriter, request *http.Request) {
query := request.URL.Query()
statement := `UPDATE Users
SET firstname = '%s',
lastname = '%s',
phone = '%s',
password='%s'
WHERE id = %s;`
sql.Execute(statement,
query.Get("firstname"),
query.Get("lastname"),
query.Get("phone"),
hashAndSalt(query.Get("password")),
query.Get("id"))
response.WriteHeader(200)
}
Implicit Messaging: Boundaries
HTTP bleeds all over the application
.NET: System.Web.HttpContext.Current.Request...
Implicit Messaging: Intention?
I know! I'll use a DTO that corresponds to my table!
Hello, Ruby on Rails / Active Record
type User struct {
ID int
FirstName string
LastName string
Phone string
Password []byte
}
Staring at the table salt: implicit or inferred understanding
type User struct {
ID int
FirstName string
LastName string
Phone string
Password []byte
}
Solution #1: Explicit Contracts
Application Protocols 101:
HTTP: Hypertext Transfer Protocol
SMTP: Simple Mail Transfer Protocol
FTP: File Transfer Protocol (control channel, port 21)
Transfering what?
Messages!
Review HTTP, SMTP, etc. RFC specifications
e.g. HTTP message body, HTTP message headers, etc.
HTTP, SMTP, etc. encapsulate a message
DTOs: What Are Your Intentions?
Implicit / Inferred (Active Record)
type User struct {
ID int
FirstName string
LastName string
Phone string
Password []byte
}
Explicit
type ChangePasswordCommand struct {
UserID int
NewPassword string
NewPasswordConfirmed string
OldPassword string
}
Messaging How-To
HTTP values into message struct
URL+VERB determines message type
Query String
Form Values
Deserialize body or HTTP 400
Messaging How-To (continued)
HTTP is an interface to application
Push message into application layer
Additional interfaces, e.g. SMTP, AMQP, CLI, etc.
1990ism #2: Complex Threading Code
Goroutine per HTTP request
Terrible for shared state like:
Incrementing a counter
Modify a map
Updating object references
Goroutine per request = manual synchronization of shared state
Go doesn't save us from synchronization code
go keyword can make things harder
package main
import "fmt"
import "time"
func main() {
for i := 0; i < 4; i++ {
go func() {
fmt.Println(i) // bad closure
}()
}
time.Sleep(time.Millisecond)
}
Solution #2: In-process "microservices" (Actors)
Actor Example:
// uncontended state
func listen() {
for message := this.incomingChannel {
// single-threaded with synchronization primitives
counter++
map[message.UserID]++
// additional message processing code
this.outgoingChannel <- message
}
}
The Unix Way: Small & Composable
Message In, Message Out: Easy Testing
Pipes and Filters
Marshal to external process
Break Apart Stateful and Stateless Operations
func (this CounterPhase) listen() {
for message := this.incomingChannel {
counter++ // stateful; single-threaded with no sync code
message.Sequence = counter
this.outgoingChannel <- message // outgoing to process phase
}
}
func (this ProcessPhase) listen() {
// can be stateless because state was assigned in previous phase
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
for message := this.incomingChannel { // incoming from counter phase
// process message (CPU/network operations)
this.outgoingChannel <- message
}
}()
}
}
HTTP RPC
Block the caller until the work is done
func handle(w http.ResponseWriter, r *http.Request) {
var wg sync.WaitGroup
wg.Add(1)
query := r.URL.Query()
this.application <- ChangePasswordCommand{
UserID: cookie.Get("user-id"),
OldPassword: query.Get("old-password"),
NewPassword: query.Get("new-password"),
NewPasswordConfirmed: query.Get("new-password-confirmed"),
WaitGroup: &wg,
}
wg.Wait()
// return result of application
}
Queues and Natural Backpressure
Typical performance characteristics at 90% vs 99% utilization
1990ism #3: Remote Procedure Call Everywhere
Fallacies of Distributed Computing
The Network is Reliable
Latency is Zero
Typical Application Behavior (Transaction Script)
Opens a DB connection
Start a transaction
Execute DB operation(s)
Other operations? (Send email, etc.)
Commit transaction
Wash, rinse, repeat
What could possibly go wrong?
Fragile RPC
Per business demands, we add "one more thing", e.g. email, etc.
When network is down, lots of things break
Bill credit card, send email, etc.
Netflix architecture
Solution #3: Actors (again) + Embrace Failure
Simple Retry Code
import "time"
func listen() {
// simple retry
for message := range this.incoming {
for attempt := 0; attempt < 5; attempt++ {
if err := emailReceipt(message); err != nil {
time.Sleep(time.Second * 30)
continue
}
}
}
}
BONUS POINTS: Simple Batching
Story: Moving one box at a time
func listen() {
for message := range this.incoming {
addToUnitOfWork(message)
if len(this.incoming) == 0 || len(batch) >= 100 {
commit()
newTransaction()
}
}
}
1-2 order of magnitude performance increase
1990ism #4: Abuse Garbage Collection
Primitive, mark-and-sweep implementation
But getting better...
Java and .NET
pointers
maps
strings
slices
GC Pause Latency and You
Are 500 ms GC pauses okay?
How about 5 seconds?
What is latency costing you?
Solution #4: Understanding GC Behavior
Measure, measure, measure
Avoid pointers (where possible)
Preallocate and re-use structures (where possible)
My bug report (issue #9477) & maps of structs (v1.5)
Keep byte slices off heap (where possible)
Size of the heap
1990ism #5: Logging Is Sufficient
Logging is awesome, but very "trees" focused
Stored?
Where?
How long?
Who analyzes and when?
Calls to log.Print result in blocking syscalls that yield the goroutine
Hard to make blocking/yielding calls
Solution #5: Metrics, Metrics, Everywhere
Business Value (Coda Hale: Metrics, Metrics, Everywhere)
Business value is anything which makes people more likely to give us money
We want to generate more business value
Our code generates business value when it runs—NOT when we write it.
We need to make better decisions about our code
We need to know what our code does when it runs
We can’t do this unless we MEASURE it
Our mental model of our code is not our code.
Example: This code can’t possibly work; it works.
Example: This code can’t fail; it fails
Example: Do these changes make things faster?
We can’t know until we MEASURE it
We improve our mental model by measuring what our code DOES
A better mental model makes us better at deciding what to do—at generating business
value
Understanding Your Application
Instrument your application (metrics)
Understand how it's being used
Understand the pathways that are taken (counters)
Understand how much (disk/memory/etc) you have left (gauges)
Service Providers
Librato (http://github.com/smartystreets/metrics)
Boundary
Datadog
Key Takeaways
Go != other languages
Work with concurrency primitives
Explicit messages
Message pipelines ("actors")
Simple logic, simple code
Thank you
3 Mar 2015
Jonathan Oliver
@jonathan_oliver(http://twitter.com/jonathan_oliver)
http://jonathanoliver.com(http://jonathanoliver.com)
http://github.com/joliver(http://github.com/joliver)
http://keybase.com/joliver(http://keybase.com/joliver)
Distributed Podcast
Chief SmartyPants, SmartyStreets

More Related Content

What's hot

Cosmos SDK Workshop: How to Build a Blockchain from Scratch
Cosmos SDK Workshop: How to Build a Blockchain from ScratchCosmos SDK Workshop: How to Build a Blockchain from Scratch
Cosmos SDK Workshop: How to Build a Blockchain from Scratch
Tendermint Inc
 
Chronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conferenceChronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conference
Peter Lawrey
 
Kerberos
KerberosKerberos
Kerberos
Sutanu Paul
 
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
Casey Bisson
 
Greyhound - Powerful Pure Functional Kafka Library
Greyhound - Powerful Pure Functional Kafka LibraryGreyhound - Powerful Pure Functional Kafka Library
Greyhound - Powerful Pure Functional Kafka Library
Natan Silnitsky
 
WebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST MicroserviceWebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST Microservice
Rick Hightower
 
Advanced Microservices Caching Patterns - Devoxx UK
Advanced Microservices Caching Patterns - Devoxx UKAdvanced Microservices Caching Patterns - Devoxx UK
Advanced Microservices Caching Patterns - Devoxx UK
Natan Silnitsky
 
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-087 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
Casey Bisson
 
Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0
StreamNative
 
Ntlm Unsafe
Ntlm UnsafeNtlm Unsafe
Ntlm Unsafe
Guang Ying Yuan
 
Micro on NATS - Microservices with Messaging
Micro on NATS - Microservices with MessagingMicro on NATS - Microservices with Messaging
Micro on NATS - Microservices with Messaging
Apcera
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBus
Particular Software
 
Deep Dive In To Kerberos
Deep Dive In To KerberosDeep Dive In To Kerberos
Deep Dive In To Kerberos
Ishan A B Ambanwela
 
Chenli linux-kerne-community
Chenli linux-kerne-communityChenli linux-kerne-community
Chenli linux-kerne-community
力 陈
 
.NET Fest 2019. Irina Scurtu. Forget about HTTP
.NET Fest 2019. Irina Scurtu. Forget about HTTP.NET Fest 2019. Irina Scurtu. Forget about HTTP
.NET Fest 2019. Irina Scurtu. Forget about HTTP
NETFest
 
How Zhaopin contributes to Pulsar community
How Zhaopin contributes to Pulsar communityHow Zhaopin contributes to Pulsar community
How Zhaopin contributes to Pulsar community
StreamNative
 
OpenSlava Infrastructure Automation Patterns
OpenSlava   Infrastructure Automation PatternsOpenSlava   Infrastructure Automation Patterns
OpenSlava Infrastructure Automation Patterns
Antons Kranga
 
Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service Architecture
Linjith Kunnon
 
Webinar: Building Web Applications with MongoDB and Spring
Webinar: Building Web Applications with MongoDB and Spring Webinar: Building Web Applications with MongoDB and Spring
Webinar: Building Web Applications with MongoDB and Spring
MongoDB
 
OpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosOpenStack and OpenFlow Demos
OpenStack and OpenFlow Demos
Brent Salisbury
 

What's hot (20)

Cosmos SDK Workshop: How to Build a Blockchain from Scratch
Cosmos SDK Workshop: How to Build a Blockchain from ScratchCosmos SDK Workshop: How to Build a Blockchain from Scratch
Cosmos SDK Workshop: How to Build a Blockchain from Scratch
 
Chronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conferenceChronicle Accelerate Crypto Investor conference
Chronicle Accelerate Crypto Investor conference
 
Kerberos
KerberosKerberos
Kerberos
 
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
The lies we tell our code, LinuxCon/CloudOpen 2015-08-18
 
Greyhound - Powerful Pure Functional Kafka Library
Greyhound - Powerful Pure Functional Kafka LibraryGreyhound - Powerful Pure Functional Kafka Library
Greyhound - Powerful Pure Functional Kafka Library
 
WebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST MicroserviceWebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST Microservice
 
Advanced Microservices Caching Patterns - Devoxx UK
Advanced Microservices Caching Patterns - Devoxx UKAdvanced Microservices Caching Patterns - Devoxx UK
Advanced Microservices Caching Patterns - Devoxx UK
 
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-087 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
7 characteristics of container-native infrastructure, Docker Zurich 2015-09-08
 
Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0Transaction Support in Pulsar 2.5.0
Transaction Support in Pulsar 2.5.0
 
Ntlm Unsafe
Ntlm UnsafeNtlm Unsafe
Ntlm Unsafe
 
Micro on NATS - Microservices with Messaging
Micro on NATS - Microservices with MessagingMicro on NATS - Microservices with Messaging
Micro on NATS - Microservices with Messaging
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBus
 
Deep Dive In To Kerberos
Deep Dive In To KerberosDeep Dive In To Kerberos
Deep Dive In To Kerberos
 
Chenli linux-kerne-community
Chenli linux-kerne-communityChenli linux-kerne-community
Chenli linux-kerne-community
 
.NET Fest 2019. Irina Scurtu. Forget about HTTP
.NET Fest 2019. Irina Scurtu. Forget about HTTP.NET Fest 2019. Irina Scurtu. Forget about HTTP
.NET Fest 2019. Irina Scurtu. Forget about HTTP
 
How Zhaopin contributes to Pulsar community
How Zhaopin contributes to Pulsar communityHow Zhaopin contributes to Pulsar community
How Zhaopin contributes to Pulsar community
 
OpenSlava Infrastructure Automation Patterns
OpenSlava   Infrastructure Automation PatternsOpenSlava   Infrastructure Automation Patterns
OpenSlava Infrastructure Automation Patterns
 
Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service Architecture
 
Webinar: Building Web Applications with MongoDB and Spring
Webinar: Building Web Applications with MongoDB and Spring Webinar: Building Web Applications with MongoDB and Spring
Webinar: Building Web Applications with MongoDB and Spring
 
OpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosOpenStack and OpenFlow Demos
OpenStack and OpenFlow Demos
 

Viewers also liked

Science education in the philippines 1960s
Science education in the philippines 1960sScience education in the philippines 1960s
Science education in the philippines 1960s
Lyn Agustin
 
Journey in the Basic Education Curricular reforms
Journey in the Basic Education Curricular reformsJourney in the Basic Education Curricular reforms
Journey in the Basic Education Curricular reforms
Paul Christian
 
Curriculum and instruction
Curriculum and instructionCurriculum and instruction
Curriculum and instruction
Mark Anthony Peralta
 
Postmodernism
PostmodernismPostmodernism
Postmodernism
LouiseAllen
 
Philippine education presentation
Philippine education presentationPhilippine education presentation
Philippine education presentation
Carlo Magno
 
Introduction to post modernism
Introduction to post modernismIntroduction to post modernism
Introduction to post modernism
quintus
 
Curriculum models (Philippines' Curriculum Models)
Curriculum models (Philippines' Curriculum Models)Curriculum models (Philippines' Curriculum Models)
Curriculum models (Philippines' Curriculum Models)
TeacherAdora
 

Viewers also liked (7)

Science education in the philippines 1960s
Science education in the philippines 1960sScience education in the philippines 1960s
Science education in the philippines 1960s
 
Journey in the Basic Education Curricular reforms
Journey in the Basic Education Curricular reformsJourney in the Basic Education Curricular reforms
Journey in the Basic Education Curricular reforms
 
Curriculum and instruction
Curriculum and instructionCurriculum and instruction
Curriculum and instruction
 
Postmodernism
PostmodernismPostmodernism
Postmodernism
 
Philippine education presentation
Philippine education presentationPhilippine education presentation
Philippine education presentation
 
Introduction to post modernism
Introduction to post modernismIntroduction to post modernism
Introduction to post modernism
 
Curriculum models (Philippines' Curriculum Models)
Curriculum models (Philippines' Curriculum Models)Curriculum models (Philippines' Curriculum Models)
Curriculum models (Philippines' Curriculum Models)
 

Similar to The 1990s Called. They Want Their Code Back.

CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
Insider Threat Visualization - HITB 2007, Kuala Lumpur
Insider Threat Visualization - HITB 2007, Kuala LumpurInsider Threat Visualization - HITB 2007, Kuala Lumpur
Insider Threat Visualization - HITB 2007, Kuala Lumpur
Raffael Marty
 
Insider Threat Visualization - HackInTheBox 2007
Insider Threat Visualization - HackInTheBox 2007Insider Threat Visualization - HackInTheBox 2007
Insider Threat Visualization - HackInTheBox 2007
Raffael Marty
 
Docker interview Questions-3.pdf
Docker interview Questions-3.pdfDocker interview Questions-3.pdf
Docker interview Questions-3.pdf
Yogeshwaran R
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
Alexandre Moneger
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)
Sri Prasanna
 
Streaming 101: Hello World
Streaming 101:  Hello WorldStreaming 101:  Hello World
Streaming 101: Hello World
Josh Fischer
 
Scaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, GoalsScaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, Goals
kamaelian
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnel
ukdpe
 
Idempotency of commands in distributed systems
Idempotency of commands in distributed systemsIdempotency of commands in distributed systems
Idempotency of commands in distributed systems
Max Małecki
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Ambassador Labs
 
Bootcamp Introduction.pptx
Bootcamp Introduction.pptxBootcamp Introduction.pptx
Bootcamp Introduction.pptx
AyanMurmu
 
XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)
Kiran Jonnalagadda
 
Computer network (10)
Computer network (10)Computer network (10)
Computer network (10)
NYversity
 
Top Java Performance Problems and Metrics To Check in Your Pipeline
Top Java Performance Problems and Metrics To Check in Your PipelineTop Java Performance Problems and Metrics To Check in Your Pipeline
Top Java Performance Problems and Metrics To Check in Your Pipeline
Andreas Grabner
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
IndicThreads
 
Simplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 TeachersSimplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 Teachers
webhostingguy
 
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
HostedbyConfluent
 
What I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleWhat I learned about APIs in my first year at Google
What I learned about APIs in my first year at Google
Tim Burks
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Talentica Software
 

Similar to The 1990s Called. They Want Their Code Back. (20)

CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
Insider Threat Visualization - HITB 2007, Kuala Lumpur
Insider Threat Visualization - HITB 2007, Kuala LumpurInsider Threat Visualization - HITB 2007, Kuala Lumpur
Insider Threat Visualization - HITB 2007, Kuala Lumpur
 
Insider Threat Visualization - HackInTheBox 2007
Insider Threat Visualization - HackInTheBox 2007Insider Threat Visualization - HackInTheBox 2007
Insider Threat Visualization - HackInTheBox 2007
 
Docker interview Questions-3.pdf
Docker interview Questions-3.pdfDocker interview Questions-3.pdf
Docker interview Questions-3.pdf
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)
 
Streaming 101: Hello World
Streaming 101:  Hello WorldStreaming 101:  Hello World
Streaming 101: Hello World
 
Scaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, GoalsScaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, Goals
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnel
 
Idempotency of commands in distributed systems
Idempotency of commands in distributed systemsIdempotency of commands in distributed systems
Idempotency of commands in distributed systems
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
 
Bootcamp Introduction.pptx
Bootcamp Introduction.pptxBootcamp Introduction.pptx
Bootcamp Introduction.pptx
 
XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)
 
Computer network (10)
Computer network (10)Computer network (10)
Computer network (10)
 
Top Java Performance Problems and Metrics To Check in Your Pipeline
Top Java Performance Problems and Metrics To Check in Your PipelineTop Java Performance Problems and Metrics To Check in Your Pipeline
Top Java Performance Problems and Metrics To Check in Your Pipeline
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
 
Simplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 TeachersSimplified Networking and Troubleshooting for K-12 Teachers
Simplified Networking and Troubleshooting for K-12 Teachers
 
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
Next Gen Data Modeling in the Open Data Platform With Doron Porat and Liran Y...
 
What I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleWhat I learned about APIs in my first year at Google
What I learned about APIs in my first year at Google
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 

Recently uploaded

留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
bseovas
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
bseovas
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Florence Consulting
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
cuobya
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
Laura Szabó
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
ukwwuq
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 

Recently uploaded (20)

留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 

The 1990s Called. They Want Their Code Back.

  • 1. The 1990s Called. They Want Their Code Back. 5 Ways Your Code is Stuck in the 90s 3 Mar 2015 Jonathan Oliver
  • 3. Overview Disclaimers Why Go Exists #1 Implicit messaging #2 Complex Threading #3 RPC Everywhere #4 GC #5 Logging Conclusion
  • 4. Caveats: But, but, but... Your mileage may vary Don't apply blindly or wholesale Sharp knife
  • 5. Our experience C# on Windows vs Go on Linux (512 req/s) hdrhistogram.org
  • 6. C# Windows vs Golang Linux at 4096 req/s hdrhistogram.org
  • 7. C# Windows vs Golang Linux at 8192 req/s hdrhistogram.org
  • 8. Why Go Exists (The real reason) Compile times? Multi-core, networked systems
  • 10. Hint Dropping Fallacy If you have to ask, it doesn't mean as much If you really loved me, you'd know
  • 11. Implicit Messaging: PHP <?php $sql = 'UPDATE Users SET ' + 'firstname = ' $_GET['firstname'] + ','+ 'lastname = ' $_GET['lastname'] + ','+ 'phone = ' $_GET['phone'] + ','+ 'password = ' hash($_GET['password']) + ','+ 'WHERE id=' + $_GET['id']; mysql_query($sql, $connection) or die("Couldn't execute query."); ?>
  • 12. Implicit Messaging: Go Where does HTTP stop and the application start? func implicit(response http.ResponseWriter, request *http.Request) { query := request.URL.Query() statement := `UPDATE Users SET firstname = '%s', lastname = '%s', phone = '%s', password='%s' WHERE id = %s;` sql.Execute(statement, query.Get("firstname"), query.Get("lastname"), query.Get("phone"), hashAndSalt(query.Get("password")), query.Get("id")) response.WriteHeader(200) }
  • 13. Implicit Messaging: Boundaries HTTP bleeds all over the application .NET: System.Web.HttpContext.Current.Request...
  • 14. Implicit Messaging: Intention? I know! I'll use a DTO that corresponds to my table! Hello, Ruby on Rails / Active Record type User struct { ID int FirstName string LastName string Phone string Password []byte } Staring at the table salt: implicit or inferred understanding
  • 15. type User struct { ID int FirstName string LastName string Phone string Password []byte }
  • 17. Application Protocols 101: HTTP: Hypertext Transfer Protocol SMTP: Simple Mail Transfer Protocol FTP: File Transfer Protocol (control channel, port 21) Transfering what?
  • 18. Messages! Review HTTP, SMTP, etc. RFC specifications e.g. HTTP message body, HTTP message headers, etc. HTTP, SMTP, etc. encapsulate a message
  • 19. DTOs: What Are Your Intentions? Implicit / Inferred (Active Record) type User struct { ID int FirstName string LastName string Phone string Password []byte } Explicit type ChangePasswordCommand struct { UserID int NewPassword string NewPasswordConfirmed string OldPassword string }
  • 20. Messaging How-To HTTP values into message struct URL+VERB determines message type Query String Form Values Deserialize body or HTTP 400
  • 21. Messaging How-To (continued) HTTP is an interface to application Push message into application layer Additional interfaces, e.g. SMTP, AMQP, CLI, etc.
  • 22. 1990ism #2: Complex Threading Code
  • 23. Goroutine per HTTP request Terrible for shared state like: Incrementing a counter Modify a map Updating object references
  • 24. Goroutine per request = manual synchronization of shared state Go doesn't save us from synchronization code go keyword can make things harder package main import "fmt" import "time" func main() { for i := 0; i < 4; i++ { go func() { fmt.Println(i) // bad closure }() } time.Sleep(time.Millisecond) }
  • 25. Solution #2: In-process "microservices" (Actors)
  • 26. Actor Example: // uncontended state func listen() { for message := this.incomingChannel { // single-threaded with synchronization primitives counter++ map[message.UserID]++ // additional message processing code this.outgoingChannel <- message } } The Unix Way: Small & Composable Message In, Message Out: Easy Testing Pipes and Filters Marshal to external process
  • 27. Break Apart Stateful and Stateless Operations func (this CounterPhase) listen() { for message := this.incomingChannel { counter++ // stateful; single-threaded with no sync code message.Sequence = counter this.outgoingChannel <- message // outgoing to process phase } } func (this ProcessPhase) listen() { // can be stateless because state was assigned in previous phase for i := 0; i < runtime.NumCPU(); i++ { go func() { for message := this.incomingChannel { // incoming from counter phase // process message (CPU/network operations) this.outgoingChannel <- message } }() } }
  • 28. HTTP RPC Block the caller until the work is done func handle(w http.ResponseWriter, r *http.Request) { var wg sync.WaitGroup wg.Add(1) query := r.URL.Query() this.application <- ChangePasswordCommand{ UserID: cookie.Get("user-id"), OldPassword: query.Get("old-password"), NewPassword: query.Get("new-password"), NewPasswordConfirmed: query.Get("new-password-confirmed"), WaitGroup: &wg, } wg.Wait() // return result of application }
  • 29. Queues and Natural Backpressure Typical performance characteristics at 90% vs 99% utilization
  • 30. 1990ism #3: Remote Procedure Call Everywhere
  • 31. Fallacies of Distributed Computing The Network is Reliable Latency is Zero
  • 32. Typical Application Behavior (Transaction Script) Opens a DB connection Start a transaction Execute DB operation(s) Other operations? (Send email, etc.) Commit transaction Wash, rinse, repeat What could possibly go wrong?
  • 33. Fragile RPC Per business demands, we add "one more thing", e.g. email, etc. When network is down, lots of things break Bill credit card, send email, etc. Netflix architecture
  • 34. Solution #3: Actors (again) + Embrace Failure
  • 35. Simple Retry Code import "time" func listen() { // simple retry for message := range this.incoming { for attempt := 0; attempt < 5; attempt++ { if err := emailReceipt(message); err != nil { time.Sleep(time.Second * 30) continue } } } }
  • 36. BONUS POINTS: Simple Batching Story: Moving one box at a time func listen() { for message := range this.incoming { addToUnitOfWork(message) if len(this.incoming) == 0 || len(batch) >= 100 { commit() newTransaction() } } } 1-2 order of magnitude performance increase
  • 37. 1990ism #4: Abuse Garbage Collection
  • 38. Primitive, mark-and-sweep implementation But getting better... Java and .NET pointers maps strings slices
  • 39.
  • 40. GC Pause Latency and You Are 500 ms GC pauses okay? How about 5 seconds? What is latency costing you?
  • 42. Measure, measure, measure Avoid pointers (where possible) Preallocate and re-use structures (where possible) My bug report (issue #9477) & maps of structs (v1.5) Keep byte slices off heap (where possible) Size of the heap
  • 43. 1990ism #5: Logging Is Sufficient
  • 44. Logging is awesome, but very "trees" focused Stored? Where? How long? Who analyzes and when? Calls to log.Print result in blocking syscalls that yield the goroutine Hard to make blocking/yielding calls
  • 45. Solution #5: Metrics, Metrics, Everywhere
  • 46. Business Value (Coda Hale: Metrics, Metrics, Everywhere) Business value is anything which makes people more likely to give us money
  • 47. We want to generate more business value
  • 48. Our code generates business value when it runs—NOT when we write it.
  • 49. We need to make better decisions about our code
  • 50. We need to know what our code does when it runs
  • 51. We can’t do this unless we MEASURE it
  • 52. Our mental model of our code is not our code.
  • 53. Example: This code can’t possibly work; it works.
  • 54. Example: This code can’t fail; it fails
  • 55. Example: Do these changes make things faster?
  • 56. We can’t know until we MEASURE it
  • 57. We improve our mental model by measuring what our code DOES
  • 58. A better mental model makes us better at deciding what to do—at generating business value
  • 59.
  • 60. Understanding Your Application Instrument your application (metrics) Understand how it's being used Understand the pathways that are taken (counters) Understand how much (disk/memory/etc) you have left (gauges)
  • 63. Go != other languages Work with concurrency primitives Explicit messages Message pipelines ("actors") Simple logic, simple code
  • 64. Thank you 3 Mar 2015 Jonathan Oliver @jonathan_oliver(http://twitter.com/jonathan_oliver) http://jonathanoliver.com(http://jonathanoliver.com) http://github.com/joliver(http://github.com/joliver) http://keybase.com/joliver(http://keybase.com/joliver) Distributed Podcast Chief SmartyPants, SmartyStreets