SlideShare a Scribd company logo
1 of 51
C100K And Go
Kai Ding
tracymacding@gmail.com
Outline
• C100K problem
• Go
• Example
• Go vs Nginx
• Go stack
• Go schedule
• Go network
C100K
• The C100K problem is the problem of optimising
network sockets to handle a large number of clients
at the same time.The name C100K is a numeronym
for concurrently handling one hundred thousand
connections.
C100K: Key point
Memory
• the less, the better
Scheduler
• the faster, the better
Complexity
• the simple, the better
Solutions
• serve one client with each server thread, use blocking I/O
• Serve many clients with each thread, use nonblocking I/O and
level-triggered readiness notification
• Serve many clients with each thread, use nonblocking I/O and
readiness change notification
• Serve many clients with each thread, use asynchronous I/O
• Build the server code into the kernel
• Others …
• serve one client with each server thread, use blocking I/O
• Simple
• Memory
• ~1MB*100K = 100GB
• Scheduler
• maintain 100K kernel threads in RB tree(using NPTL)
• thread switch (~30 us) (http://blog.tsunanet.net/2010/11/how-long-does-it-
take-to-make-context.html)
Solution
• Serve many clients with each thread, use nonblocking I/O
• Complexity
• using epoll: can’t deal with file IO
• using thread pool or async API to deal with file IO
• Memory
• Low: numCPU * 1MB
• Scheduler
• Low
• Serve many clients with each thread, use asynchronous I/O
• Complexity
• Highest
• Limitation: only support direct io
• Memory
• Low: numCPU * 1MB
• Scheduler
• Low
Another Way?
Example of web server using Go
TCP Server
HTTP Server
Go vs Nginx
From: https://groups.google.com/forum/#!topic/golang-nuts/YIlpcoUPY_M
Go
• Go is an open source programming language that
makes it easy to build simple, reliable, and efficient
software.
Go routine
def: A go routine is a lightweight
thread managed by the Go runtime
Feature: Go routine has its own stack
Feature: Go routine vs system thread
(M:N M>>N)
Go stack
• Tiny stack:~2KB
• Stack grows as needed (2X each time)
• when?
• how?
Go stack
• When
particular code are insert to check stack overflow
Go stack
• How
• split stack (v1.0 ~ v1.2)
or segment stack. In this approach, stacks are discontiguous and grow
incrementally. Each stack starts with a single segment. When the stack needs to
grow, another segment is allocated and linked to the previous one, and so forth.
Each stack is effectively a doubly linked list of one or more segments.
Go stack
• continous stack (v1.3 ~ )
or copy stack. When a stack needs to grow, instead of allocating a new
segment the runtime will:
1. create a new, somewhat larger stack
2. copy the contents of the old stack to the new stack
3. re-adjust every copied pointer to point to the new addresses
4. destroy the old stack
split vs continous stack
Go scheduler
• G & M & P
• Routine state
• Schedule
• Routine switch
G & M & P
• G: represent go routine
• M: represent system thread
• P: represent processor (since go 1.1)
• G >> M >> P
Routine State
Schedule
• System call
• Channel r/w
• Preempt
Syscall
• Enter sys-call
• detach M from P (p.m = nil), but m still point to p(m.p = p)
• P state change to PSyscall (P has some Gs)
Syscall
• Exit sys-call
• if m.p is still waiting, put g into p and run
• else find a idle p and run g in it
• else put g in global queue and sleep
Syscall
• P state during syscall
• if PSyscall state last over 10ms, sysmon will take over
• P state become PIdle
• sysmon will get a new idle M to run Gs on P
Channel r/w
• if G
• read from a empty channel (a := <-c)
• write to a full channel (false->c)
• G will be scheduled out
• A brand new G will be picked and run
Preemption
• sysmon will check all P’s last schedule time
• if now - lastsched > 10ms, force running G on P to schedule
• set G.preempt = true and
• set G.stackguard0 = StackPreempt(-1314)
• next time G does function call, stack overflow check, bingo!
• during new stack, schedule
Get runnable G
• from global run queue for fairness
• from P’s local runnable G queue
• wait any G blocked on IO event(network)
• steal from other P
Routine switch
• Save old G state
sp
pc
bp
…
Extremely lightweight
Routine switch
• Restore new G state
sp
pc
bp
…
Go network
• TCP/HTTP Server Example
• Implementation(Linux)
• Some Issue
• timeout
Implementation(Linux)
• Using epoll under linux
• routines blocked on r/w will be scheduled out
• routines woken up if socket has i/o event
• sysmon will check I/O event in socket
• ……
Epoll Init
• epoll inited once go program run
New Socket
• socket created if necessary(listen & accept…)
• set socket O_NONBLOCK
• add socket into epoll queue
Read/Write
• routine blocked if read/write returns EAGAIN
Read/Write
• routine woken up in three cases
• sysmon: check socket io event periodic
• findrunnable: scheduler can’t grab runnable routine
• FinishGC: after gc ~
wake up
• epoll_wait wait utill io event
wake up
• for each socket, routine associated with it will be
woken up
socket timeout
• timeout is different from os
• os to:how long app wait if no data transferred
• go to:when will this r/w failed
socket timeout
• timeout is different from os
• os to:set once, take effective every time
• go to:set each time before r/w
• go to:more exactly than os to!
• suppose 100KB data to be read, 10KB each time

More Related Content

What's hot

Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasVirtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasFlink Forward
 
Object Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldObject Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldScyllaDB
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingLubomir Rintel
 
Couchbase live 2016
Couchbase live 2016Couchbase live 2016
Couchbase live 2016Pierre Mavro
 
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBase
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBaseHBaseCon2017 Quanta: Quora's hierarchical counting system on HBase
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBaseHBaseCon
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 
Computer network (6)
Computer network (6)Computer network (6)
Computer network (6)NYversity
 
OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?ScyllaDB
 
Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Nicolas De Loof
 
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Flink Forward
 
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overviewFlink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overviewFlink Forward
 
Using eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthUsing eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthScyllaDB
 
Benchmarking Apache Samza: 1.2 million messages per sec per node
Benchmarking Apache Samza: 1.2 million messages per sec per nodeBenchmarking Apache Samza: 1.2 million messages per sec per node
Benchmarking Apache Samza: 1.2 million messages per sec per nodeTao Feng
 
TDEA 2018 Kafka EOS (Exactly-once)
TDEA 2018 Kafka EOS (Exactly-once)TDEA 2018 Kafka EOS (Exactly-once)
TDEA 2018 Kafka EOS (Exactly-once)Erhwen Kuo
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with ErlangMaxim Kharchenko
 
Till Rohrmann – Fault Tolerance and Job Recovery in Apache Flink
Till Rohrmann – Fault Tolerance and Job Recovery in Apache FlinkTill Rohrmann – Fault Tolerance and Job Recovery in Apache Flink
Till Rohrmann – Fault Tolerance and Job Recovery in Apache FlinkFlink Forward
 
Flink Connector Development Tips & Tricks
Flink Connector Development Tips & TricksFlink Connector Development Tips & Tricks
Flink Connector Development Tips & TricksEron Wright
 

What's hot (20)

Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy FarkasVirtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
Virtual Flink Forward 2020: Autoscaling Flink at Netflix - Timothy Farkas
 
Object Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldObject Compaction in Cloud for High Yield
Object Compaction in Cloud for High Yield
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
Couchbase live 2016
Couchbase live 2016Couchbase live 2016
Couchbase live 2016
 
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBase
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBaseHBaseCon2017 Quanta: Quora's hierarchical counting system on HBase
HBaseCon2017 Quanta: Quora's hierarchical counting system on HBase
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Computer network (6)
Computer network (6)Computer network (6)
Computer network (6)
 
OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?
 
Breaking the RpiDocker challenge
Breaking the RpiDocker challenge Breaking the RpiDocker challenge
Breaking the RpiDocker challenge
 
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...Virtual Flink Forward 2020: Build your next-generation stream platform based ...
Virtual Flink Forward 2020: Build your next-generation stream platform based ...
 
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overviewFlink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
 
Using eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthUsing eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster Health
 
Benchmarking Apache Samza: 1.2 million messages per sec per node
Benchmarking Apache Samza: 1.2 million messages per sec per nodeBenchmarking Apache Samza: 1.2 million messages per sec per node
Benchmarking Apache Samza: 1.2 million messages per sec per node
 
TDEA 2018 Kafka EOS (Exactly-once)
TDEA 2018 Kafka EOS (Exactly-once)TDEA 2018 Kafka EOS (Exactly-once)
TDEA 2018 Kafka EOS (Exactly-once)
 
Rust Primer
Rust PrimerRust Primer
Rust Primer
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Till Rohrmann – Fault Tolerance and Job Recovery in Apache Flink
Till Rohrmann – Fault Tolerance and Job Recovery in Apache FlinkTill Rohrmann – Fault Tolerance and Job Recovery in Apache Flink
Till Rohrmann – Fault Tolerance and Job Recovery in Apache Flink
 
Tcp repair
Tcp repairTcp repair
Tcp repair
 
Bathcamp 2010-riak
Bathcamp 2010-riakBathcamp 2010-riak
Bathcamp 2010-riak
 
Flink Connector Development Tips & Tricks
Flink Connector Development Tips & TricksFlink Connector Development Tips & Tricks
Flink Connector Development Tips & Tricks
 

Similar to C100 k and go

Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_monTomas Doran
 
London devops logging
London devops loggingLondon devops logging
London devops loggingTomas Doran
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Golinuxlab_conf
 
Introduction to Go scheduler
Introduction to Go schedulerIntroduction to Go scheduler
Introduction to Go schedulerBin Wang
 
Overcoming Variable Payloads to Optimize for Performance
Overcoming Variable Payloads to Optimize for PerformanceOvercoming Variable Payloads to Optimize for Performance
Overcoming Variable Payloads to Optimize for PerformanceScyllaDB
 
What to do when detect deadlock
What to do when detect deadlockWhat to do when detect deadlock
What to do when detect deadlockSyed Zaid Irshad
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkTomas Doran
 
GPU Computing for Data Science
GPU Computing for Data Science GPU Computing for Data Science
GPU Computing for Data Science Domino Data Lab
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
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
 
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
ECS19 - Ingo Gegenwarth -  Running Exchangein large environmentECS19 - Ingo Gegenwarth -  Running Exchangein large environment
ECS19 - Ingo Gegenwarth - Running Exchange in large environmentEuropean Collaboration Summit
 
Building real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark StreamingBuilding real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark Streamingdatamantra
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLThijs Terlouw
 
Networking Architecture of Warframe
Networking Architecture of WarframeNetworking Architecture of Warframe
Networking Architecture of WarframeMaciej Siniło
 
CPAN Gems From The Far East
CPAN Gems From The Far EastCPAN Gems From The Far East
CPAN Gems From The Far Eastlestrrat
 

Similar to C100 k and go (20)

Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
London devops logging
London devops loggingLondon devops logging
London devops logging
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
 
Introduction to Go scheduler
Introduction to Go schedulerIntroduction to Go scheduler
Introduction to Go scheduler
 
Overcoming Variable Payloads to Optimize for Performance
Overcoming Variable Payloads to Optimize for PerformanceOvercoming Variable Payloads to Optimize for Performance
Overcoming Variable Payloads to Optimize for Performance
 
What to do when detect deadlock
What to do when detect deadlockWhat to do when detect deadlock
What to do when detect deadlock
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
GPU Computing for Data Science
GPU Computing for Data Science GPU Computing for Data Science
GPU Computing for Data Science
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
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...
 
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
ECS19 - Ingo Gegenwarth -  Running Exchangein large environmentECS19 - Ingo Gegenwarth -  Running Exchangein large environment
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
 
Zero mq logs
Zero mq logsZero mq logs
Zero mq logs
 
C++ scalable network_io
C++ scalable network_ioC++ scalable network_io
C++ scalable network_io
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Building real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark StreamingBuilding real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark Streaming
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NL
 
Networking Architecture of Warframe
Networking Architecture of WarframeNetworking Architecture of Warframe
Networking Architecture of Warframe
 
CPAN Gems From The Far East
CPAN Gems From The Far EastCPAN Gems From The Far East
CPAN Gems From The Far East
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

C100 k and go

  • 1. C100K And Go Kai Ding tracymacding@gmail.com
  • 2. Outline • C100K problem • Go • Example • Go vs Nginx • Go stack • Go schedule • Go network
  • 3. C100K • The C100K problem is the problem of optimising network sockets to handle a large number of clients at the same time.The name C100K is a numeronym for concurrently handling one hundred thousand connections.
  • 4. C100K: Key point Memory • the less, the better Scheduler • the faster, the better Complexity • the simple, the better
  • 5. Solutions • serve one client with each server thread, use blocking I/O • Serve many clients with each thread, use nonblocking I/O and level-triggered readiness notification • Serve many clients with each thread, use nonblocking I/O and readiness change notification • Serve many clients with each thread, use asynchronous I/O • Build the server code into the kernel • Others …
  • 6. • serve one client with each server thread, use blocking I/O • Simple • Memory • ~1MB*100K = 100GB • Scheduler • maintain 100K kernel threads in RB tree(using NPTL) • thread switch (~30 us) (http://blog.tsunanet.net/2010/11/how-long-does-it- take-to-make-context.html) Solution
  • 7. • Serve many clients with each thread, use nonblocking I/O • Complexity • using epoll: can’t deal with file IO • using thread pool or async API to deal with file IO • Memory • Low: numCPU * 1MB • Scheduler • Low
  • 8. • Serve many clients with each thread, use asynchronous I/O • Complexity • Highest • Limitation: only support direct io • Memory • Low: numCPU * 1MB • Scheduler • Low
  • 10.
  • 11. Example of web server using Go
  • 14. Go vs Nginx From: https://groups.google.com/forum/#!topic/golang-nuts/YIlpcoUPY_M
  • 15. Go • Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
  • 16.
  • 17.
  • 18.
  • 19. Go routine def: A go routine is a lightweight thread managed by the Go runtime Feature: Go routine has its own stack Feature: Go routine vs system thread (M:N M>>N)
  • 20. Go stack • Tiny stack:~2KB • Stack grows as needed (2X each time) • when? • how?
  • 21.
  • 22. Go stack • When particular code are insert to check stack overflow
  • 23. Go stack • How • split stack (v1.0 ~ v1.2) or segment stack. In this approach, stacks are discontiguous and grow incrementally. Each stack starts with a single segment. When the stack needs to grow, another segment is allocated and linked to the previous one, and so forth. Each stack is effectively a doubly linked list of one or more segments.
  • 24.
  • 25.
  • 26. Go stack • continous stack (v1.3 ~ ) or copy stack. When a stack needs to grow, instead of allocating a new segment the runtime will: 1. create a new, somewhat larger stack 2. copy the contents of the old stack to the new stack 3. re-adjust every copied pointer to point to the new addresses 4. destroy the old stack
  • 28.
  • 29. Go scheduler • G & M & P • Routine state • Schedule • Routine switch
  • 30. G & M & P • G: represent go routine • M: represent system thread • P: represent processor (since go 1.1) • G >> M >> P
  • 31.
  • 33. Schedule • System call • Channel r/w • Preempt
  • 34. Syscall • Enter sys-call • detach M from P (p.m = nil), but m still point to p(m.p = p) • P state change to PSyscall (P has some Gs)
  • 35. Syscall • Exit sys-call • if m.p is still waiting, put g into p and run • else find a idle p and run g in it • else put g in global queue and sleep
  • 36. Syscall • P state during syscall • if PSyscall state last over 10ms, sysmon will take over • P state become PIdle • sysmon will get a new idle M to run Gs on P
  • 37. Channel r/w • if G • read from a empty channel (a := <-c) • write to a full channel (false->c) • G will be scheduled out • A brand new G will be picked and run
  • 38. Preemption • sysmon will check all P’s last schedule time • if now - lastsched > 10ms, force running G on P to schedule • set G.preempt = true and • set G.stackguard0 = StackPreempt(-1314) • next time G does function call, stack overflow check, bingo! • during new stack, schedule
  • 39. Get runnable G • from global run queue for fairness • from P’s local runnable G queue • wait any G blocked on IO event(network) • steal from other P
  • 40. Routine switch • Save old G state sp pc bp … Extremely lightweight
  • 41. Routine switch • Restore new G state sp pc bp …
  • 42. Go network • TCP/HTTP Server Example • Implementation(Linux) • Some Issue • timeout
  • 43. Implementation(Linux) • Using epoll under linux • routines blocked on r/w will be scheduled out • routines woken up if socket has i/o event • sysmon will check I/O event in socket • ……
  • 44. Epoll Init • epoll inited once go program run
  • 45. New Socket • socket created if necessary(listen & accept…) • set socket O_NONBLOCK • add socket into epoll queue
  • 46. Read/Write • routine blocked if read/write returns EAGAIN
  • 47. Read/Write • routine woken up in three cases • sysmon: check socket io event periodic • findrunnable: scheduler can’t grab runnable routine • FinishGC: after gc ~
  • 48. wake up • epoll_wait wait utill io event
  • 49. wake up • for each socket, routine associated with it will be woken up
  • 50. socket timeout • timeout is different from os • os to:how long app wait if no data transferred • go to:when will this r/w failed
  • 51. socket timeout • timeout is different from os • os to:set once, take effective every time • go to:set each time before r/w • go to:more exactly than os to! • suppose 100KB data to be read, 10KB each time