Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.
-
date post
22-Dec-2015 -
Category
Documents
-
view
218 -
download
0
Transcript of Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.
![Page 1: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/1.jpg)
Basic Networking & Interprocess Communication
Vivek Pai
Nov 27, 2001
![Page 2: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/2.jpg)
2
Everyone’s Getting Sick
Including me– Didn’t assign reading in syllabus– Did get rough grades computed– Still have one feedback missing– Putting off new project this week
![Page 3: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/3.jpg)
3
Mechanics
Next project assigned next Tuesday Only 5 projects instead of 6 Target: use threads, synchronization
– Probably using webserver again– Not building on filesystem– Suggestions welcome
We’ve completely neglected the dining philosophers problem!
![Page 4: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/4.jpg)
4
Dining Philosophers
![Page 5: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/5.jpg)
5
Possible Solutions
Philosophers go in order Place numbers on forks If stuck, drop fork, try again Defer by age or some other quantity Stab each other
![Page 6: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/6.jpg)
6
Deadlock “Solutions”
Eliminate parallelism Order resources, grab in order Determine priorities on contention Restart & randomize
Deadlock performance: cost of avoiding/detecting deadlock versus work frequency & work thrown away
![Page 7: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/7.jpg)
7
Original Lecture Goals
Basic networking - Introduce the basics of networking, the new semantics versus standard file system calls, and how this affects the programming model. Discuss network basics such as naming, ports, connections, protocols, etc.
Interprocess communication - Show how “networking” is useful within a single machine to communicate data. Give examples of different domains, how they are implemented, and the effects within the kernel. Show how networking and interprocess communication can be used to allow easy distribution of applications.
![Page 8: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/8.jpg)
8
Communication
You’ve already seen some of it– Web server project(s)
Machines have “names”– Human-readable names are convenience– “Actual” name is IP (Internet Protocol) address– For example, 127.0.0.1 means “this machine”– nslookup www.cs.princeton.edu gives
128.112.136.11
![Page 9: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/9.jpg)
9
Names & Services
Multiple protocols– ssh, ftp, telnet, http, etc.– How do we know how to connect?
Machines also have port numbers– 16 bit quantity (0-65535)– Protocols have default port #– Can still do “telnet 128.112.136.11 80”
![Page 10: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/10.jpg)
10
But The Web Is Massive
Possible names >> possible IP addresses– World population > possible IP addresses
– Many names map to same IP addr
– Use extra information to disambiguate
– In HTTP, request contains “Host: name” header Many connections to same (machine, port #)
– Use (src addr, src port, dst addr, dst port) to identify connection
![Page 11: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/11.jpg)
11
Circuit Switching versus Packet Switching
Circuit – reserve resources in advance– Hold resources for entire communication– Example: phone line
Packet – break data into small pieces– Pieces identify themselves, “share” links– Individual pieces routed to destination– Example: internet– Problem: no guarantee pieces reach
![Page 12: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/12.jpg)
12
Who Got Rich By Packet Switching?
![Page 13: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/13.jpg)
13
The “End To End” Argument
Don’t rely on lower layers of the system to ensure something happens
If it needs to occur, build the logic into the endpoints
Implications:– Intermediate components simplified– Repetition possible at endpoints (use OS)
What is reliability?
![Page 14: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/14.jpg)
14
Do Applications Care?
Some do Most don’t
– Use whatever OS provides– Good enough for most purposes
What do applications want?– Performance– Simplicity
![Page 15: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/15.jpg)
15
Reading & Writing
A file:– Is made into a “descriptor” via some call– Is an unstructured stream of bytes– Can be read/written– OS provides low-level interaction– Applications use read/write calls
Sounds workable?
![Page 16: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/16.jpg)
16
Network Connections As FDs
Network connection usually called “socket” Interesting new system calls
– socket( ) – creates an fd for networking use– connect( ) – connects to the specified machine– bind( ) – specifies port # for this socket– listen( ) – waits for incoming connections– accept( ) – gets connection from other machine
And, of course, read( ) and write( )
![Page 17: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/17.jpg)
17
New Semantics
Doing a write( )– What’s the latency/bandwidth of a disk?– When does a write( ) “complete”?– Where did data actually go before?– Can we do something similar now?
What about read( )– When should a read return?– What should a read return?
![Page 18: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/18.jpg)
18
Buffering
Provided by OS– Memory on both sender and receiver sides– Sender: enables reliability, quick writes– Receiver: allows incoming data before read
Example – assume slow network– write(fd, buf, size);– memset(buf, 0, size)– write(fd, buf, size);
![Page 19: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/19.jpg)
19
Interprocess Communications
Shared memory– Threads sharing address space– Processes memory-mapping the same file– Processes using shared memory system calls
Sockets and read/write– Nothing prohibits connection to same machine– Even faster mechanism – different “domain”– Unix domain (local) versus Internet (either)
![Page 20: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/20.jpg)
20
Sockets vs Shared Memory
Sockets– Higher overhead– No common parent/file needed– Synchronous operation
Shared memory– Locking due to synchronous operation– Fast reads/writes – no OS intervention– Harder to use multiple machines
![Page 21: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/21.jpg)
21
Even More Semantics
How do you express the following:– Do (task) until (message received)– Do (this task) until (receiver not ready)– Do (task) until (no more data)
Problem: implies knowing system behavior Related: what happens when buffer
fills/empties? (hint: think of filesystem)
![Page 22: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/22.jpg)
22
Synchronous vs Asynchronous
Synchronous: do it now, wait until over Asynchronous: start it now, check later
Somewhat related: Blocking: wait until it’s all done Nonblocking: only do what can be done
without blocking
![Page 23: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/23.jpg)
23
Transferring Large Files
OS buffers are 16-64KB Large files are >> buffer size Assume two clients
– Each requests a different large file– Both are on slow networks
How do you design your server?
![Page 24: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/24.jpg)
24
Server Design Choices
Processes– Each client handled by a different process
Threads– Each client handled by a different thread
Single process– Use nonblocking operations, multiplex
![Page 25: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/25.jpg)
25
Processing Steps
Read File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Headerend
![Page 26: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/26.jpg)
26
Blocking Steps
Read File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Headerend
Network Blocking
Disk Blocking
![Page 27: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/27.jpg)
27
Concurrency Architecture
Overlap disk, network, & application-level processing
Architecture how steps are overlapped
Note: implications for performance
![Page 28: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/28.jpg)
28
Multiple Processes (MP)
Pro: simple programming – rely on OSCons: too many processes
caching harder
Process 1Read File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Header
Process NRead File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Header
![Page 29: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/29.jpg)
29
Multiple Threads (MT)
Pro: shared address spacelower “context switch” overhead
Cons: many threadsrequires kernel thread supportsynchronization needed
Read File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Header
![Page 30: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/30.jpg)
30
Single Process Event Driven (SPED)
Pro: single address spaceno synchronization
Cons: must explicitly handle piecesin practice, disk reads still block
Read File
Send Data
Accept
Conn
Read
Request
Find
File
Send
Header
Event Dispatcher
![Page 31: Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.](https://reader036.fdocuments.net/reader036/viewer/2022062516/56649d795503460f94a5ce6d/html5/thumbnails/31.jpg)
31
Homework
Read about the select( ) system call Reading from syllabus I may send an e-mail with papers