Carnegie Mellon 1 Proxy Web & Concurrency Rohith Jagannathan April 13 th, 2015 15/18-213: Introduction to Computer Systems Recitation 13.

Slides:



Advertisements
Similar presentations
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
Advertisements

Review: –What functionality is supported by IP? –What IP does not do? –How many classes of IP addresses? –Explain fields in an IP header? –How subnet works?
1 Carnegie Mellon Proxylab and stuff : Introduction to Computer Systems Recitation 13: November 19, 2012 Donald Huang (donaldh) Section M.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
1 Carnegie Mellon Networking Basics and Concurrent Programming Shiva (sshankar) Section M.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
Carnegie Mellon 1 Proxy Web & Concurrency Ian Hartwig 15/ Section E Recitation 13 April 15 th, 2013.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
UNIX Sockets COS 461 Precept 1.
INTRODUCTION TO WEB DATABASE PROGRAMMING
IT 210 The Internet & World Wide Web introduction.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
Assignment 3 A Client/Server Application: Chatroom.
Elementary TCP Sockets
Client-Side Network Programming
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
FTP (File Transfer Protocol) & Telnet
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
How Web Servers and the Internet Work by by: Marshall Brainby: Marshall Brain
HOW WEB SERVER WORKS? By- PUSHPENDU MONDAL RAJAT CHAUHAN RAHUL YADAV RANJIT MEENA RAHUL TYAGI.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
1 Welcome to CSC 301 Web Programming Charles Frank.
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Remote Shell CS230 Project #4 Assigned : Due date :
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming Lab 1 1CS Computer Networks.
Carnegie Mellon 1 Proxy: Web & Concurrency : Introduction to Computer Systems Recitation 13: Monday, Nov. 18 th, 2013 Marjorie Carlson Section A.
Carnegie Mellon 1 Proxy Recitation Jeffrey Liu Recitation 13: November 23, 2015.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
Carnegie Mellon Recitation 11: ProxyLab Fall 2009 November 16, 2009 Including Material from Previous Semesters' Recitations.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Assignment 3 A Client/Server Application: Chatroom
Block 5: An application layer protocol: HTTP
Web Development Web Servers.
UNIX Sockets COS 461 Precept 1.
E-commerce | WWW World Wide Web - Concepts
Extending echo server HTTP Broken pipe error Feedback and evaluation
E-commerce | WWW World Wide Web - Concepts
Tutorial on Socket Programming
Recitation 12: ProxyLab Part 1
CSCI 380: Operating Systems Lecture #14 Instructor: William Killian
Server-side Programming CSE 333 Autumn 2018
Server-side Programming CSE 333 Summer 2018
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Internet Networking recitation #8
Presentation transcript:

Carnegie Mellon 1 Proxy Web & Concurrency Rohith Jagannathan April 13 th, /18-213: Introduction to Computer Systems Recitation 13

Carnegie Mellon 2 Outline Getting content on the web: Telnet/cURL Demo  How the web really works Networking Basics Proxy  Due Tuesday, April 28th  No late days  No partners this year String Manipulation in C

Carnegie Mellon 3 The Web in a Textbook Client request page, server provides, transaction done. A sequential server can handle this. We just need to serve one page at a time. This works great for simple text pages with embedded styles. Web server Web client (browser)

Carnegie Mellon 4 Telnet/Curl Demo Telnet  Interactive remote shell – like ssh without security  Must build HTTP request manually  This can be useful if you want to test response to malformed headers ~]% telnet 80 Trying Connected to WWW-CMU-PROD-VIP.ANDREW.cmu.edu ( ). Escape character is '^]'. GET HTTP/1.0 HTTP/ Moved Permanently Date: Sat, 11 Apr :54:39 GMT Server: Apache/ (Unix) mod_gzip/ a mod_pubcookie/3.3.4a mod_ssl/ OpenSSL/0.9.8e- fips-rhel5 Location: Connection: close Content-Type: text/html; charset=iso Moved Permanently Moved Permanently The document has moved here. Apache/ Server at Port 80 Connection closed by foreign host.

Carnegie Mellon 5 Telnet/cURL Demo cURL  “URL transfer library” with a command line program  Builds valid HTTP requests for you!  Can also be used to generate HTTP proxy requests: ~]% curl Moved Permanently Moved Permanently The document has moved here. Apache/ Server at Port 80 ~]% curl --proxy lemonshark.ics.cs.cmu.edu: Moved Permanently Moved Permanently The document has moved here. Apache/ Server at Port 80

Carnegie Mellon 6 How the Web Really Works In reality, a single HTML page today may depend on 10s or 100s of support files (images, stylesheets, scripts, etc.) Builds a good argument for concurrent servers  Just to load a single modern webpage, the client would have to wait for 10s of back-to-back request  I/O is likely slower than processing, so back Caching is simpler if done in pieces rather than whole page  If only part of the page changes, no need to fetch old parts again  Each object (image, stylesheet, script) already has a unique URL that can be used as a key

Carnegie Mellon 7 How the Web Really Works Excerpt from Carnegie Mellon University | CMU...

Carnegie Mellon 8 Sequential Proxy

Carnegie Mellon 9 Sequential Proxy Note the sloped shape of when requests finish  Although many requests are made at once, the proxy does not accept a new job until it finishes the current one  Requests are made in batches. This results from how HTML is structured as files that reference other files. Compared to the concurrent example (next), this page takes a long time to load with just static content

Carnegie Mellon 10 Concurrent Proxy

Carnegie Mellon 11 Concurrent Proxy Now, we see much less purple (waiting), and less time spent overall. Notice how multiple green (receiving) blocks overlap in time  Our proxy has multiple connections open to the browser to handle several tasks at once

Carnegie Mellon 12 How the Web Really Works A note on AJAX (and XMLHttpRequests)  Normally, a browser will make the initial page request then request any supporting files  And XMLHttpRequest is simply a request from the page once it has been loaded & the scripts are running  The distinction does not matter on the server side – everything is an HTTP Request

Carnegie Mellon 13 Outline Getting content on the web: Telnet/cURL Demo  How the web really works Networking Basics Proxy  Due Tuesday, April 28th  No late days  No partners this year String Manipulation in C

14 Carnegie Mellon Sockets What is a socket?  To an application, a socket is a file descriptor that lets the application read/write from/to the network  (all Unix I/O devices, including networks, are modeled as files) Clients and servers communicate with each other by reading from and writing to socket descriptors The main difference between regular file I/O and socket I/O is how the application “opens” the socket descriptors

15 Carnegie Mellon Overview of the Sockets Interface Client / Server Session ClientServer socket bind listen rio_readlineb rio_writenrio_readlineb rio_writen Connection request rio_readlineb close EOF Await connection request from next client open_listenfd open_clientfd acceptconnect getaddrinfo

Carnegie Mellon 16 Host and Service Conversion: getaddrinfo getaddrinfo is the modern way to convert string representations of host, ports, and service names to socket address structures.  Replaces obsolete gethostbyname - unsafe because it returns a pointer to a static variable Advantages:  Reentrant (can be safely used by threaded programs).  Allows us to write portable protocol-independent code(IPv4 and IPv6)  Given host and service, getaddrinfo returns result that points to a linked list of addrinfo structs, each pointing to socket address struct, which contains arguments for sockets APIs. getnameinfo is the inverse of getaddrinfo, converting a socket address to the corresponding host and service.

Sockets API int socket(int domain, int type, int protocol);  Create a file descriptor for network communication  used by both clients and servers  int sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);  One socket can be used for two-way communication int bind(int socket, const struct sockaddr *address, socklen_t address_len);  Associate a socket with an IP address and port number  used by servers  struct sockaddr_in sockaddr – family, address, port 17 Carnegie Mellon

Sockets API int listen(int socket, int backlog);  socket: socket to listen on  used by servers  backlog: maximum number of waiting connections  err = listen(sock_fd, MAX_WAITING_CONNECTIONS); int accept(int socket, struct sockaddr *address, socklen_t *address_len);  used by servers  socket: socket to listen on  address: pointer to sockaddr struct to hold client information after accept returns  return: file descriptor 18 Carnegie Mellon

Sockets API int connect(int socket, struct sockaddr *address, socklen_t address_len);  attempt to connect to the specified IP address and port described in address  used by clients int close(int fd);  used by both clients and servers  (also used for file I/O)  fd: socket fd to close 19 Carnegie Mellon

Sockets API ssize_t read(int fd, void *buf, size_t nbyte);  used by both clients and servers  (also used for file I/O)  fd: (socket) fd to read from  buf: buffer to read into  nbytes: buf length ssize_t write(int fd, void *buf, size_t nbyte);  used by both clients and servers  (also used for file I/O)  fd: (socket) fd to write to  buf: buffer to write  nbytes: buf length 20 Carnegie Mellon

21 Outline Getting content on the web: Telnet/cURL Demo  How the web really works Networking Basics Proxy  Due Tuesday, April 28th  No late days  No partners this year String Manipulation in C

Carnegie Mellon 22 Proxy - Functionality Should work on vast majority of sites  Reddit, Vimeo, CNN, NY Times, etc.  Some features of sites which require the POST operation (sending data to the website), will not work  Logging in to websites, sending Facebook message  HTTPS is not expected to work  Google, YouTube (and some other popular websites) now try to push users to HTTPs by default; watch out for that Cache previous requests  Use LRU eviction policy  Must allow for concurrent reads while maintaining consistency  Details in write up

Carnegie Mellon 23 Proxy - Functionality Why a multi-threaded cache? Sequential cache would bottleneck parallel proxy Multiple threads can read cached content safely Search cache for the right data and return it Two threads can read from the same cache block But what about writing content? Overwrite block while another thread reading? Two threads writing to same cache block?

Carnegie Mellon 24 Proxy - How Proxies are a bit special - they are a server and a client at the same time. They take a request from one computer (acting as the server), and make it on their behalf (as the client). Ultimately, the control flow of your program will look like a server, but will have to act as a client to complete the request Start small  Grab yourself a copy of the echo server (pg. 910) and client (pg. 909) in the book  Also review the tiny.c basic web server code to see how to deal with HTTP headers  Note that tiny.c ignores these; you may not

Carnegie Mellon 25 Proxy - How What you end up with will resemble: Server (port 80) Client Client socket address :51213 Server socket address :80 Proxy Proxy server socket address :15213 Proxy client socket address :52943

Carnegie Mellon 26 Summary Step 1: Sequential Proxy  Works great for simple text pages with embedded styles Step 2: Concurrent Proxy  multi-threading Step 3 : Cache Web Objects  Cache individual objects, not the whole page  Use an LRU eviction policy  Your caching system must allow for concurrent reads while maintaining consistency. Concurrency? Shared Resource?

Carnegie Mellon 27 Proxy – Testing & Grading New: Autograder ./driver.sh will run the same tests as autolab:  Ability to pull basic web pages from a server  Handle a (concurrent) request while another request is still pending  Fetch a web page again from your cache after the server has been stopped  This should help answer the question “is this what my proxy is supposed to do?”  Please don’t use this grader to definitively test your proxy; there are many things not tested here

Carnegie Mellon 28 Proxy – Testing & Grading Test your proxy liberally  The web is full of special cases that want to break your proxy  Generate a port for yourself with./port-for-user.pl [andrewid]  Generate more ports for web servers and such with./free-port.sh  Consider using your andrew web space (~/www) to host test files  You have to visit to publish your folder to the public server Create a handin file with make handin  Will create a tar file for you with the contents of your proxylab- handin folder

Carnegie Mellon 29 Tips: Version Control What is Git?  Version control software  Easily roll back to previous version if needed  Already installed on Andrew machines  Set up a repo on GitHub, BitBucket, or AFS  Make sure only can access it! Using Git  git pull  git add.  git commit -m “I changed something”  git push

Carnegie Mellon 30 Outline Getting content on the web: Telnet/cURL Demo  How the web really works Networking Basics Proxy  Due Tuesday, April 28th  No late days  No partners this year String Manipulation in C

Carnegie Mellon 31 String manipulation in C sscanf: Read input in specific format int sscanf(const char *str, const char *format, …); Example: buf = “213 is awesome” // Read integer and string separated by white space from buffer ‘buf’ // into passed variables ret = sscanf(buf, “%d %s %s”, &course, str1, str2); This results in: course = 213, str1 = is, str2 = awesome, ret = 3

Carnegie Mellon 32 String manipulation (cont) sprintf: Write input into buffer in specific format int sprintf(char *str, const char *format, …); Example: buf[100]; str = “213 is awesome” // Build the string in double quotes (“”) using the passed arguments // and write to buffer ‘buf’ sprintf(buf, “String (%s) is of length %d”, str, strlen(str)); This results in: buf = String (213 is awesome) is of length 14

Carnegie Mellon 33 String manipulation (cont) Other useful string manipulation functions: strcmp, strncmp, strncasecmp strstr strlen strcpy, strncpy

Carnegie Mellon 34 Aside: Setting up Firefox to use a proxy You may use any browser, but we’ll be grading with Firefox Preferences > Advanced > Network > Settings… (under Connection) Check “Use this proxy for all protocols” or your proxy will appear to work for HTTPS traffic.

Carnegie Mellon 35 Acknowledgements Slides derived from recitation slides of last 2 years by  Shiva  Hartaj Singh Dugal  Ian Hartwig

Carnegie Mellon 36 Questions?