Lec 4
Lec 4
• Today:
• TCP
• Socket programming
• Remote Procedure Calls
Assignment Reminder
• Start early
– Most assignments will be simple IF you start thinking about the design
early and get help in labs/office hours
– Systems projects take ~3X the time estimate
• Probability of email response = O(Time to deadline)
– Emailing day of deadline → Can’t provide helpful response
– Canvas discussion board: increased chance of response from TA’s and
other students
• “Head fake”: The assignments are not for teaching distributed systems.
– They are a way to get “comfortable” with uncertainty and frustration.
– Hence the loose specification and sometimes ambiguous descriptions
Client-server architecture
Server:
• always-on host
Server • permanent IP address
• data centers for scaling
Clients:
• communicate with server
• may be intermittently
connected
Client Client
• may have dynamic IP
addresses
• do not communicate
directly with each other
TCP: Overview RFCs: 793,1122,1323,
2018, 2581
User
types
‘C’
Seq=42, ACK=79, data = ‘C’
host ACKs
receipt of
‘C’, echoes
Seq=79, ACK=43, data = ‘C’ back ‘C’
host ACKs
receipt
of echoed
‘C’ Seq=43, ACK=80
time
Transport Layer 3-12
TCP Performance
• Roughly, max throughput = Window size/RTT
• Throughput = 1/RTT*(sqrt(2/3)*packet-loss-probability)
• TCP performance also depends on receive buffer sizes
Socket programming with
UDP
UDP: no “connection” between client &
server
• no handshaking before sending data
• sender explicitly attaches IP destination address
and port # to each packet
• rcvr extracts sender IP address and port# from
received packet
UDP: transmitted data may be lost or
received out-of-order
Application viewpoint:
• UDP provides unreliable transfer of groups of
bytes (“datagrams”) between client and server
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application 2-15
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(socket.AF_INET,
server socket.SOCK_DGRAM)
get user keyboard message = raw_input(’Input lowercase sentence:’)
input
clientSocket.sendto(message,(serverName, serverPort))
Attach server name, port to
message; send into socket modifiedMessage, serverAddress =
read reply characters from clientSocket.recvfrom(2048)
socket into string
print modifiedMessage
clientSocket.close()
print out received string
and close socket
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Netstat:
application
(www browser,
debug status
packet
analyzer
email client) of ports
application
OS
packet Transport (TCP/UDP)
capture copy of all Network (IP)
Ethernet Link (Ethernet)
(pcap) frames
sent/receive Physical
d
Remote Procedure Calls
Remote Procedure Calls
• Procedure (function) calls a well known and understood
mechanism for transfer of data and control within a
program/process
• Remote Procedure Calls : extend conventional local calls
to work across processes.
• Processes may be running on different machines
• Allows communication of data via function parameters and
return values
• RPC invocations also serve as notifications (transfer of
control)
RPC Example
update_temp(device, temp)
• Getters and setter methods created for each message during compilation
(protoc)
• Access via msg.fieldname() (for example, point.x())
• Multiple languages supported
gRPC: A Modern RPC Framework
• “Service” : Function declaration
• Unary: Single response for a request
• Streaming: Multiple streaming requests result in single response
• Uses HTTP/2 as transport
• Messages are just POST requests. Request name is URI, params is
content
• Can multiplex multiple requests onto single TCP connection
• At-most-once failure semantics, but other schemes using
retries possible
• Can use load balancers
• GRPC Python: https://www.semantics3.com/blog/a-simplified-
guide-to-grpc-in-python-6c4e25f0c506/
Summary
• RPCs make distributed computations look like local
computations
• Issues:
• Parameter passing
• Binding
• Failure handling
• Case Study: SUN RPC