Course Description
- Teach common network programming techniques by examples
- Focus on server-side TCP network programming on Linux
- Walk-through code in C++, Python and Go
Prerequisites
- Have read Unix Network Programming volume 1 (either 2nd ed. or 3rd ed.) by late W. Richard Stevens
- Know basics of TCP/IP, eg. IP addresses, ports,
- Know how to write an echo server with basic sockets APIs in any language
Code
- http://github.com/chenshuo/muduo
- http://github.com/chenshuo/recipes
- http://github.com/chenshuo/muduo-protorpc
- http://github.com/chenshuo/muduo-examples-in-go
Schedule
0. Overview
- Measure throughput of TCP over Gigabit Ethernet with netcat
- Lecture section 1 | Lecture section 2 | Lecture section 3
Part I: Basic non-concurrent programs with blocking IO
1. TTCP
- Review basic Sockets API
- Measure throughput of TCP over Gigabit Ethernet with TTCP
- TCP self connection
- Lecture section 4 | section 5 | section 6 | section 7 | section 8 | section 9
2. Round-trip
- How NTP works
- Measure clock error between two hosts
- The only UDP example
- Lecture section 10 | section 11 | section 12 | section 13 | section 14 | section 15 | section 16
3. Netcat
- The Swiss army knife of networking
- Deal with two file descriptors simultaneously (stdin/out and TCP socket)
- Why IO-multiplexing must be used with non-blocking IO
- Lecture section 17 | section 18 | section 19 | section 20 | section 21 | section 22 | section 23
Part II: Concurrent programs with non-blocking IO
4. procmon
- cpu / memory usage charts of one process
- dummyload
- Lecture section 25 | section 25 | section 26 | section 27 | section 28 | section 29
5. Simple memcached
- Customize the data structure
- Efficient locking by sharding
- Performance testing
- Lecture section 30 | section 31 | section 32 | section 33 | section 34 | section 35 | section 36 | section 37 |
6. Sudoku Solver
- Request-response model
- Client connections are independent
- Concurrency and parallel on multicore machines
- Disable Nagle's algorithm in low-latency servers
- Load balancing
- Overload protection
- Lecture section 38 | section 39 | section 40 | section 41 | section 42 | section 43 | section 44 | section 45 | section 46 | section 47 | section 48 | section 49 | section 50 |
7. Broadcasting to TCP peers
- Connections exchange data with each other
- How to deal with slow clients?
- Lecture section 51 | section 52 | section 53 | section 54 | section 55 | section 56 |
8. SOCKS proxy server
- Relay two TCP connections
- Mismatching bandwidth?
- Difference between level 4 and level 7?
- Lecture section 57 | section 58 | section 59 | section 60 | section 61 | section 62 | section 63 | section 64 | section 65 | section 66 | section 67 | section 68 |
Part III: Data processing with multiple machines
9. Parallel N-queen puzzle
- Multithreaded N-queen puzzle
- Multi-machine N-queen puzzle using MapReduce
- Lecture section 69 | section 70 | section 71 | section 72 | section 73 | section 74 |
10. Median across machines
11. Most frequent queries
- Lecture section 79 | section 80 | section 81 | section 82 | section 83 | section 84 |