• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Dive into network_programming
 

Dive into network_programming

on

  • 918 views

 

Statistics

Views

Total Views
918
Views on SlideShare
376
Embed Views
542

Actions

Likes
1
Downloads
8
Comments
1

3 Embeds 542

http://lilialexlee.blogspot.com 540
http://lilialexlee.blogspot.tw 1
http://lilialexlee.blogspot.jp 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • good
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Dive into network_programming Dive into network_programming Presentation Transcript

    • 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