SlideShare a Scribd company logo
1 of 21
Download to read offline
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Dive into Socket Programming
LiLi
August 16, 2013
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
OutLine
Some Basics of TCP/IP Protocol
TIME WAIT CLOSE WAIT
SO REUSEADDR SO LINGER
TCP NODELY TCP QUICKACK
Socket Buffer
SIG PIPE
KeepAlive
close shudown
Notes for Building Your Own Sockets Application
Manage Your Own Application-Layer Buffer
Async Connect/Accept
Thundering Herd
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
OutLine
Common Server Models
thread-per-connection
reactor
reactor + worker thread
multiple reactors
Common Client Models
connection pool
async io + event loop
Others
C10k C100k ...
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
TIME WAIT CLOSE WAIT
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
TIME WAIT CLOSE WAIT
active close —— TIME WAIT
passive close —— CLOSE WAIT
read returns 0
peer has closed connection, invoke close
TIME WAIT will last 2MSL max segment lifetime
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
SO REUSERADDR SO LINGER
SO REUSEADDR
when server crashes, the port remains in TIME WAIT. Server
can’t restart immediately?
set SO REUSEADDR
SO LINGER
Can set SO LINGER to prevent entering TIME WAIT. This
also discards any unsent data.
don’t do this!!! why?
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
TCP NODELY TCP QUICKACK
TCP NODELY
Nagle’s algorithm
TCP CORK
when transmit files
TCP QUICKACK
delayed ack
must set the option every time
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Socket Buffer
buffer size = 2 * Bandwidth * Delay
how to measure delay?
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
SIG PIPE
Write a Closed Socket Twice:
first time, ok, receive RST
second time, SIG PIPE, crash
Ignore the Signal:
signal(SIGPIPE,SIG IGN)
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
KeepAlive
KeepAlive option
Too Long, 2 hours 11mins you know peer is dead
Heartbeat in your own application
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
close shutdown
shutdown can only shutdown one direction
shutdown write,can still read
shutdown does not close the file descriptor,still need close
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Manage Your Own Application-Layer Buffer
read
can read all one time ?
write
can write all one time ?
trigered from event loop
read to your own buffer
write from your own buffer
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Async Connect/Accept
Blocked connect/accept
Maybe Too Long
Async accept
EWOULDBLOCK
add listen fd to event loop
Async connect
EINPROCESS
add connect fd to event loop
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Thundering Herd
accept
no longer a problem in kernel now
epoll wait
still a problem
how to solve?
lighthttpd
nginx
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
thread-per-connection
create a new thread for each connection
Before NIO,Java use this
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
reactor
simple event loop
Example:
Redis
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
reactor+ worker thread
event loop + worker thead pool
Example:
tbnet
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
multiple reactors
event loop each thread/process
Example:
memcached
nginx
lighthttpd
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
connection pool
create a set pf connection each client
Example:
Jedis
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
async io + event loop
event loop
Example:
Mina
tbnet
LiLi Dive into Socket Programming
Some Basics of TCP/IP Protocol
Notes for Building Your Own Sockets Application
Common Server Models
Common Client Models
Other
Other
C10k C100k
epoll
1000Mbit/s one event loop —by zeromq guide
C1M C10M...
More Challenges:
softirq
memory
...
dive into kernel
LiLi Dive into Socket Programming

More Related Content

What's hot

Cisco usNIC libfabric provider
Cisco usNIC libfabric providerCisco usNIC libfabric provider
Cisco usNIC libfabric providerJeff Squyres
 
Fun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-byFun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-byJeff Squyres
 
Open MPI SC'15 State of the Union BOF
Open MPI SC'15 State of the Union BOFOpen MPI SC'15 State of the Union BOF
Open MPI SC'15 State of the Union BOFJeff Squyres
 
Tech Days 2015: SPARK 2014
Tech Days 2015: SPARK 2014Tech Days 2015: SPARK 2014
Tech Days 2015: SPARK 2014AdaCore
 
OSDC 2017 - Casey Callendrello -The evolution of the Container Network Interface
OSDC 2017 - Casey Callendrello -The evolution of the Container Network InterfaceOSDC 2017 - Casey Callendrello -The evolution of the Container Network Interface
OSDC 2017 - Casey Callendrello -The evolution of the Container Network InterfaceNETWAYS
 
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019Grid Dynamics
 
libcurl, seven SSL libraries and one SSH library
libcurl, seven SSL libraries and one SSH librarylibcurl, seven SSL libraries and one SSH library
libcurl, seven SSL libraries and one SSH libraryDaniel Stenberg
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the HoodC4Media
 
Tech Days 2015: Multi-language Programming with GPRbuild
Tech Days 2015: Multi-language Programming with GPRbuildTech Days 2015: Multi-language Programming with GPRbuild
Tech Days 2015: Multi-language Programming with GPRbuildAdaCore
 
Orion RESTful git API
Orion RESTful git APIOrion RESTful git API
Orion RESTful git APITomasz Zarna
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the HoodC4Media
 
Real-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCReal-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCAlexandre Gouaillard
 
LF_DPDK17_Lagopus Router
LF_DPDK17_Lagopus RouterLF_DPDK17_Lagopus Router
LF_DPDK17_Lagopus RouterLF_DPDK
 
Open MPI State of the Union X SC'16 BOF
Open MPI State of the Union X SC'16 BOFOpen MPI State of the Union X SC'16 BOF
Open MPI State of the Union X SC'16 BOFJeff Squyres
 
Swift should I switch?
Swift should I switch?Swift should I switch?
Swift should I switch?wulfgeng
 
WebRTC Standards & Implementation Q&A - Legacy API Support Changes
WebRTC Standards & Implementation Q&A - Legacy API Support ChangesWebRTC Standards & Implementation Q&A - Legacy API Support Changes
WebRTC Standards & Implementation Q&A - Legacy API Support ChangesAmir Zmora
 
zebra & openconfigd Introduction
zebra & openconfigd Introductionzebra & openconfigd Introduction
zebra & openconfigd IntroductionKentaro Ebisawa
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experienceAlexandre Abadie
 

What's hot (20)

Cisco usNIC libfabric provider
Cisco usNIC libfabric providerCisco usNIC libfabric provider
Cisco usNIC libfabric provider
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Fun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-byFun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-by
 
netfilter programming
netfilter programmingnetfilter programming
netfilter programming
 
Open MPI SC'15 State of the Union BOF
Open MPI SC'15 State of the Union BOFOpen MPI SC'15 State of the Union BOF
Open MPI SC'15 State of the Union BOF
 
Tech Days 2015: SPARK 2014
Tech Days 2015: SPARK 2014Tech Days 2015: SPARK 2014
Tech Days 2015: SPARK 2014
 
OSDC 2017 - Casey Callendrello -The evolution of the Container Network Interface
OSDC 2017 - Casey Callendrello -The evolution of the Container Network InterfaceOSDC 2017 - Casey Callendrello -The evolution of the Container Network Interface
OSDC 2017 - Casey Callendrello -The evolution of the Container Network Interface
 
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019
MPL: modular pipeline library - Dynamic Talks Milwaukee 4/11/2019
 
libcurl, seven SSL libraries and one SSH library
libcurl, seven SSL libraries and one SSH librarylibcurl, seven SSL libraries and one SSH library
libcurl, seven SSL libraries and one SSH library
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the Hood
 
Tech Days 2015: Multi-language Programming with GPRbuild
Tech Days 2015: Multi-language Programming with GPRbuildTech Days 2015: Multi-language Programming with GPRbuild
Tech Days 2015: Multi-language Programming with GPRbuild
 
Orion RESTful git API
Orion RESTful git APIOrion RESTful git API
Orion RESTful git API
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the Hood
 
Real-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCReal-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTC
 
LF_DPDK17_Lagopus Router
LF_DPDK17_Lagopus RouterLF_DPDK17_Lagopus Router
LF_DPDK17_Lagopus Router
 
Open MPI State of the Union X SC'16 BOF
Open MPI State of the Union X SC'16 BOFOpen MPI State of the Union X SC'16 BOF
Open MPI State of the Union X SC'16 BOF
 
Swift should I switch?
Swift should I switch?Swift should I switch?
Swift should I switch?
 
WebRTC Standards & Implementation Q&A - Legacy API Support Changes
WebRTC Standards & Implementation Q&A - Legacy API Support ChangesWebRTC Standards & Implementation Q&A - Legacy API Support Changes
WebRTC Standards & Implementation Q&A - Legacy API Support Changes
 
zebra & openconfigd Introduction
zebra & openconfigd Introductionzebra & openconfigd Introduction
zebra & openconfigd Introduction
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
 

Similar to Dive into network_programming

Netty Cookbook - Chapter 2
Netty Cookbook - Chapter 2Netty Cookbook - Chapter 2
Netty Cookbook - Chapter 2Trieu Nguyen
 
ORTC Library - Introduction
ORTC Library - IntroductionORTC Library - Introduction
ORTC Library - IntroductionErik Lagerway
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxssuser23035c
 
Using Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadieUsing Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadiePôle Systematic Paris-Region
 
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux DeviceAdding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux DeviceSamsung Open Source Group
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using JavaRahul Hada
 
Porting To Symbian
Porting To SymbianPorting To Symbian
Porting To SymbianMark Wilcox
 
CCCNA R&S-02-The TCP-IP and OSI Networking Models
CCCNA R&S-02-The TCP-IP and OSI Networking ModelsCCCNA R&S-02-The TCP-IP and OSI Networking Models
CCCNA R&S-02-The TCP-IP and OSI Networking ModelsAmir Jafari
 
Developer-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDeveloper-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDevOps Indonesia
 
Docker network Present in VietNam DockerDay 2015
Docker network Present in VietNam DockerDay 2015Docker network Present in VietNam DockerDay 2015
Docker network Present in VietNam DockerDay 2015Van Phuc
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterAnne Nicolas
 
Hotplug and Virtio - Tetsuya Mukawa
Hotplug and Virtio - Tetsuya MukawaHotplug and Virtio - Tetsuya Mukawa
Hotplug and Virtio - Tetsuya Mukawaharryvanhaaren
 
Ryu SDN Framework
Ryu SDN FrameworkRyu SDN Framework
Ryu SDN FrameworkAPNIC
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server InternalsPraveen Gollakota
 

Similar to Dive into network_programming (20)

Netty Cookbook - Chapter 2
Netty Cookbook - Chapter 2Netty Cookbook - Chapter 2
Netty Cookbook - Chapter 2
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Sockets
Sockets Sockets
Sockets
 
Tomcat openssl
Tomcat opensslTomcat openssl
Tomcat openssl
 
ORTC Library - Introduction
ORTC Library - IntroductionORTC Library - Introduction
ORTC Library - Introduction
 
Client server
Client serverClient server
Client server
 
Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
Tomcat openssl
Tomcat opensslTomcat openssl
Tomcat openssl
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
Using Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre AbadieUsing Python for IoT: a return of experience, Alexandre Abadie
Using Python for IoT: a return of experience, Alexandre Abadie
 
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux DeviceAdding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using Java
 
Porting To Symbian
Porting To SymbianPorting To Symbian
Porting To Symbian
 
CCCNA R&S-02-The TCP-IP and OSI Networking Models
CCCNA R&S-02-The TCP-IP and OSI Networking ModelsCCCNA R&S-02-The TCP-IP and OSI Networking Models
CCCNA R&S-02-The TCP-IP and OSI Networking Models
 
Developer-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDeveloper-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for Kubernetes
 
Docker network Present in VietNam DockerDay 2015
Docker network Present in VietNam DockerDay 2015Docker network Present in VietNam DockerDay 2015
Docker network Present in VietNam DockerDay 2015
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
 
Hotplug and Virtio - Tetsuya Mukawa
Hotplug and Virtio - Tetsuya MukawaHotplug and Virtio - Tetsuya Mukawa
Hotplug and Virtio - Tetsuya Mukawa
 
Ryu SDN Framework
Ryu SDN FrameworkRyu SDN Framework
Ryu SDN Framework
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Dive into network_programming

  • 1. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Dive into Socket Programming LiLi August 16, 2013 LiLi Dive into Socket Programming
  • 2. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other OutLine Some Basics of TCP/IP Protocol TIME WAIT CLOSE WAIT SO REUSEADDR SO LINGER TCP NODELY TCP QUICKACK Socket Buffer SIG PIPE KeepAlive close shudown Notes for Building Your Own Sockets Application Manage Your Own Application-Layer Buffer Async Connect/Accept Thundering Herd LiLi Dive into Socket Programming
  • 3. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other OutLine Common Server Models thread-per-connection reactor reactor + worker thread multiple reactors Common Client Models connection pool async io + event loop Others C10k C100k ... LiLi Dive into Socket Programming
  • 4. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other TIME WAIT CLOSE WAIT LiLi Dive into Socket Programming
  • 5. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other TIME WAIT CLOSE WAIT active close —— TIME WAIT passive close —— CLOSE WAIT read returns 0 peer has closed connection, invoke close TIME WAIT will last 2MSL max segment lifetime LiLi Dive into Socket Programming
  • 6. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other SO REUSERADDR SO LINGER SO REUSEADDR when server crashes, the port remains in TIME WAIT. Server can’t restart immediately? set SO REUSEADDR SO LINGER Can set SO LINGER to prevent entering TIME WAIT. This also discards any unsent data. don’t do this!!! why? LiLi Dive into Socket Programming
  • 7. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other TCP NODELY TCP QUICKACK TCP NODELY Nagle’s algorithm TCP CORK when transmit files TCP QUICKACK delayed ack must set the option every time LiLi Dive into Socket Programming
  • 8. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Socket Buffer buffer size = 2 * Bandwidth * Delay how to measure delay? LiLi Dive into Socket Programming
  • 9. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other SIG PIPE Write a Closed Socket Twice: first time, ok, receive RST second time, SIG PIPE, crash Ignore the Signal: signal(SIGPIPE,SIG IGN) LiLi Dive into Socket Programming
  • 10. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other KeepAlive KeepAlive option Too Long, 2 hours 11mins you know peer is dead Heartbeat in your own application LiLi Dive into Socket Programming
  • 11. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other close shutdown shutdown can only shutdown one direction shutdown write,can still read shutdown does not close the file descriptor,still need close LiLi Dive into Socket Programming
  • 12. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Manage Your Own Application-Layer Buffer read can read all one time ? write can write all one time ? trigered from event loop read to your own buffer write from your own buffer LiLi Dive into Socket Programming
  • 13. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Async Connect/Accept Blocked connect/accept Maybe Too Long Async accept EWOULDBLOCK add listen fd to event loop Async connect EINPROCESS add connect fd to event loop LiLi Dive into Socket Programming
  • 14. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Thundering Herd accept no longer a problem in kernel now epoll wait still a problem how to solve? lighthttpd nginx LiLi Dive into Socket Programming
  • 15. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other thread-per-connection create a new thread for each connection Before NIO,Java use this LiLi Dive into Socket Programming
  • 16. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other reactor simple event loop Example: Redis LiLi Dive into Socket Programming
  • 17. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other reactor+ worker thread event loop + worker thead pool Example: tbnet LiLi Dive into Socket Programming
  • 18. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other multiple reactors event loop each thread/process Example: memcached nginx lighthttpd LiLi Dive into Socket Programming
  • 19. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other connection pool create a set pf connection each client Example: Jedis LiLi Dive into Socket Programming
  • 20. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other async io + event loop event loop Example: Mina tbnet LiLi Dive into Socket Programming
  • 21. Some Basics of TCP/IP Protocol Notes for Building Your Own Sockets Application Common Server Models Common Client Models Other Other C10k C100k epoll 1000Mbit/s one event loop —by zeromq guide C1M C10M... More Challenges: softirq memory ... dive into kernel LiLi Dive into Socket Programming