CPS110: More NetworksVirtual/physical interfacesOrdered messagesSlide 4Slide 5Slide 6Reliable messagesDetecting and fixing dropsSlide 9Slide 10What about corruption?Slide 12Slide 13Byte streamsSlide 15Slide 16Slide 17SentinelsCourse administrationDistributed systemsMotivation for distributed appsSlide 22Slide 23Slide 24Building up to distributed appsSlide 26Send/receive primitivesSlide 28Slide 29Slide 30Client-serverSlide 32Producer-consumerSlide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Other approachesSlide 42Network abstractionsRemote procedure call (RPC)The RPC illusionRPC stub functionsSlide 47Slide 48RPC notesRPC exampleJava RMI exampleProblems with RPCExample RPC with pointersSlide 54Finishing RPCStructuring a concurrent systemAlternative structureRest of the semesterCPS110: More NetworksLandon CoxMarch 30, 2009Virtual/physical interfacesHardwareHardwareOSOSApplicationsApplicationsOrdered messagesNetworks can re-order IP messagesE.g. Send: A, B. Arrive: B, AHow should we fix this?Assign sequence numbers (0, 1, 2, 3, 4, …)Ordered messagesDo what for a message that arrives out of order?(0, 1, 3, 2, 4)a.Save #3 and deliver after #2 is delivered(this is what TCP does)b.Drop #3, deliver #2, deliver #4c.Deliver #3, drop #2, deliver #4b. and c. are ordered, but not reliable (messages are dropped).Relies on the reliability layer to handle lost messages.Ordered messagesFor a notion of order, first need “connections”Why?Must know which messages are related to each otherIdea in TCPOpen a connectionSend a sequence of messagesClose the connectionOpening a connection ties two sockets togetherConnection is socket-to-socket unique: only these sockets can use itSequence numbers are connection specificVirtual/physical interfacesHardwareHardwareOSOSApplicationsApplicationsReliable messagesUsually paired with orderingTCP provides both ordering and reliabilityHardware interfaceNetwork drops messagesNetwork duplicates messagesNetwork corrupts messagesApplication interfaceEvery message is delivered exactly onceDetecting and fixing dropsHow to fix a dropped message?Have sender re-send itHow does sender know it’s been dropped?Have receiver tell the senderReceiver may not know it’s been sentLike asking in the car,“If we left you at the theater, speak up.”Detecting and fixing dropsHave receiver acknowledge each messageCalled an “ACK”If sender doesn’t get an ACKAssume message has been droppedResend original messageIs this ok for the sender to assume?No. ACKs can be dropped too (or delayed)Detecting and fixing dropsPossible outcomesMessage is delayed or droppedACK is delayed or droppedStrategyDeal with all as though message was droppedWorst case if message wasn’t dropped after all?Need to deal with duplicate messagesHow to detect and fix duplicate messages?Easy. Just use the sequence number and drop duplicate.What about corruption?Messages can also be corruptedBits get flipped, etcEspecially true over wireless networksHow to deal with this?Add a checksum (a little redundancy)Checksum usually = sum of all bitsDrop corrupted messagesWhat about corruption?Dropping corrupted messages is elegantTransforms problem into a dropped messageWe already know how to deal with dropsCommon techniqueSolve one problem by transforming it into another1.Corruption drops2.Drops duplicates3.Drop any duplicate messages (very simple)Virtual/physical interfacesHardwareHardwareOSOSApplicationsApplicationsByte streamsHardware interfaceSend information in discrete messagesApplication interfaceSend data in a continuous streamLike reading/writing from/to a fileByte streamsMany apps think about info in distinct messagesWhat if you want to send more data than fits?UDP max message size is 64 KBWhat if data never ends?Streamed mediaTCP provides “byte streams” instead of messagesByte streamsSender writes messages of arbitrary sizeTCP breaks up the stream into fragmentsReassembles the fragments at destinationReceiver sees a byte streamFragments are not visible to either processProgramming the receiverMust loop until certain number of bytes arriveOtherwise, might get first fragment and returnByte streamsUDP makes boundaries visibleTCP makes boundaries invisible(loop until you get everything you need)How to know # of bytes to receive?1.Size is contained in header2.Read until you see a pattern (sentinel)3.Sender closes connectionSentinelsIdea: message is done when special pattern arrivesExample: C stringsHow do we know the end of a C string?When you reach the null-termination character (‘\0’)Ok, now say we are sending an arbitrary fileCan we use ‘\0’ as a sentinel?No. The data payload may contain ‘\0’ charsWhat can we do then?Course administrationLast day for Project 2 submissions89, 89, 89, 89, 87, 86, 83, 79, 79, 78, 76, 75, 49, 33, 28Project 3 will be out next weekHack into a serverSocket programming how-to postedRyan will cover in discussion section this weekWill post example client/server codeAny questions?Distributed systemsYou use distributed systems everyday.Both on your PC and behind the scenes.Motivation for distributed apps1. PerformanceMotivation for distributed apps1. Performance2. Co-locationCan locate computer near local resourcesExamples of local resourcesPeople, sensors, sensitive databaseMotivation for distributed apps1. Performance2. Co-location3. ReliabilityNot all computers will go down at onceDue to floods, fires, earthquakes, etcBetter chance of continuous serviceMotivation for distributed apps1. Performance2. Co-location3. Reliability4. Already have multiple machinesCan’t put everyone on one machineTry to stitch existing machines togetherBuilding up to distributed appsNeeded two things in multi-threaded programs1. Atomic primitives to control thread interleavings(interrupt disable/enable, atomic test&set)2. Way to share information between threads(shared address space)These won’t work for distributed applicationsNo interrupt disable/enable or atomic test&setNo shared memoryBuilding up to distributed appsCan only communicate through messagesSend messagesReceive messagesIf no shared data, are there race
View Full Document