Server Design Discuss Design issues for Servers Review Server Creation in Linux.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Nonblocking I/O Blocking vs. non-blocking I/O
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
CS162B: Daemonization Jacob T.Chan. Foreground Process  Has input/output capabilities  These require users at the terminal  Lives as long as the terminal.
1 Chapter 6 Datagram Delivery by UDP Just as the Internet Protocol uses the services of subnetworks, transport protocols build upon the services of IP.
Slide 1 Client / Server Paradigm. Slide 2 Outline: Client / Server Paradigm Client / Server Model of Interaction Server Design Issues C/ S Points of Interaction.
Socket Programming.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
Daemon Processes and inetd Superserver
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Concurrent vs. iterative servers
SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
ECE 4110 – Internetwork Programming Client-Server Model.
資 管 Lee Application Layer and Client-Server Model A3.
Elementary TCP Sockets
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
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.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
CCNA 1 v3.0 Module 11 TCP/IP Transport and Application Layers.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
1 Server Design Discuss Design issues for Servers Review Server Creation in Windows.
Remote Shell CS230 Project #4 Assigned : Due date :
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
Position of application layer. Application layer duties.
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
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.
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Operating Systems Process Creation
Client/Server Socket Programming Project
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Part 4: Network Applications Client-server interaction, example applications.
©The McGraw-Hill Companies, Inc., 2000© Adapted for use at JMU by Mohamed Aboutabl, 2003Mohamed Aboutabl1 1 Chapter 15 Application Layer and Client-Server.
Berkeley Socket Abstraction
UNIX Sockets Outline UNIX sockets CS 640.
©The McGraw-Hill Companies, Inc., 2000© Adapted for use at JMU by Mohamed Aboutabl, 2003Mohamed Aboutabl1 1 Chapter 16 Socket Interface.
UNIX Network Programming1 Chapter 12. Daemon Processes and inetd Superserver.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
R Some of these slides are from Prof Frank Lin SJSU. r Minor modifications are made. 1.
1 K. Salah Application Layer Module K. Salah Network layer duties.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Chapter 9: Transport Layer
Instructor Materials Chapter 9: Transport Layer
Boots Cassel Villanova University
Concurrent vs. iterative servers
CHAPTER 8 ELEMENTARY UDP SOCKETS
Client-Server Interaction
Interacting With Protocol Software
UNIX Sockets Outline Homework #1 posted by end of day
Issues in Client/Server Programming
Daemons & inetd Refs: Chapter 12.
Presentation transcript:

Server Design Discuss Design issues for Servers Review Server Creation in Linux

Server Software Design Concurrent Vs. Iterative – Concurrent servers support multiple clients concurrently (may or may not use concurrent processes) – Iterative servers support a single client at a time. (Much easier to build, but usually much less efficient) CS423 - cotter 2

Server Software Design Concurrent Vs. Iterative – Concurrent servers support multiple clients concurrently (may or may not use concurrent processes) – Iterative servers support a single client at a time. (Much easier to build, but usually much less efficient) Connection-Oriented Vs. Connectionless – Connection Oriented access is provided through TCP which provides all of the reliability for the access. – Connectionless access is provided through UDP, and requires the application to provide reliability. CS423 - cotter 3

Server Software Design Stateless Vs. Stateful Servers – Stateful servers maintain status of ongoing client communications. Use of state information can allow more efficient communication (less information needed in each message), but it does open up the possibility of state dependencies if not carefully designed into the server. – Stateless servers rely on the client to provide all of the information needed for each request. Easier to design, but generally less efficient. CS423 - cotter 4

Stateless Vs. Stateful Servers Example Client queries server for file information (ftp, database search, etc.) Stateless model: – query includes filename, offset, # of bytes to read CS423 - cotter 5

Stateless Vs. Stateful Servers Example Client queries server for file information (ftp, database search, etc.) Stateless model: – query includes filename, offset, # of bytes to read Stateful model: – server maintains table of client info current queries containing filename, current offset – client sends request to read # of bytes – server accesses buffer for info, if available,or disk file. CS423 - cotter 6

Stateless Vs. Stateful Servers CS423 - cotter 7 Filename: X Offset: 512 Buffer Pointer: Filename: Y Offset: 1024 Buffer Pointer: hash(IP, port) Buffer for file X, pointer at 512 Buffer for file Y, pointer at 1024

Basic Server Types CS423 - cotter 8 Iterative connectionless Iterative connection-oriented Concurrent connectionless Concurrent connection-oriented

Basic Server Types CS423 - cotter 9 Iterative connectionless Iterative connection-oriented Concurrent connectionless Concurrent connection-oriented

Iterative Connection-Oriented Server Create a socket & bind to the port for the service being offered. Place the socket in passive mode (listen) Accept the next connection request from the socket and obtain a new socket for the connection. Repeatedly send a request from client, formulate a response, and send response back to client. When finished with a client, close the connection & return to accept mode, waiting for a new connection. CS423 - cotter 10

Iterative Connectionless Server Create a socket and bind to the well-known address for the service being offered. Repeatedly read the next request from a client, formulate a response, and send a reply back to the client according to the application protocol. CS423 - cotter 11

Concurrent Connectionless Server (P) Create a socket & bind to the port for the service being offered. (P) Repeatedly call recvfrom to receive the next request from client, & create a new child process (c) Receive a specific request upon creation as well as access to the socket. (c) Form a reply according to application protocol and send it back to client using sendto. (c) Terminate child process upon completion of task CS423 - cotter 12

Concurrent Connection-Oriented Server (P) Create a socket & bind to the port for the service offered. Leave the socket unconnected (P) Place the socket in passive mode (listen) (P) Repeatedly call accept to receive the next request from client, & create new child process (c) Receive a connection request upon creation (c) Interact with client (read request(s) & send(s)) (c) Terminate child process upon completion of task CS423 - cotter 13

Server Issues Request processing time Vs. Observed response time CS423 - cotter 14

Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address. CS423 - cotter 15

Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address. Connectionless communications: – ans = sendto(s, buf, buflen, flags, toaddr, toaddrlen) – ans = recvfrom(s, buf, buflen, flags, toaddr, toaddrlen) CS423 - cotter 16

Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address. Connectionless communications: – ans = sendto(s, buf, buflen, flags, toaddr, toaddrlen) – ans = recvfrom(s, buf, buflen, flags, toaddr, toaddrlen) Use of exec for child processes CS423 - cotter 17

Real vs. Apparent Concurrency CS423 - cotter18 Multiple low duty cycle clients can be handled by a Single thread

Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible CS423 - cotter 19

Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible Use SELECT to wait for I/O on existing sockets CS423 - cotter 20

Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible Use select to wait for I/O on existing sockets If original socket gets request, use accept for new connection & add socket to the list If other socket responds, use read / write to communicate Return to select CS423 - cotter 21

Apparent Concurrency Select (fdsize, &fd_set_in, &fd_set_out, &fd_set_err, time) – Fdsize: Not used in Windows, but used in UNIX or Linux to indicate number of sockets that should be scanned. – &fd_set_in: Address of the file descriptor set that is monitoring sockets for pending input work – &fd_set_out: Address of the file descriptor set that is moniroting sockets for pending outgoing work. – &fd_set_err: File descriptor set that monitors for exceptions to normal work (special error messages, or urgent messages) – Time: set to NULL to wait until there is some activity. Otherwise may be set to the maximum time to wait until select function returns. CS423 - cotter 22

Running Servers in Linux For simple testing, run server in a separate terminal window as a normal console process. – If server generates console output, that output is visible – Easy to see server response / failure For ongoing service, server should run as a background process, unattached to a console. – Detach process from console with “&” – # imServer 789 & – If owner locks screen, process continues – If owner logs off, process will terminate To terminate process without logging off: – Add terminate option to program (specific command / code, etc. – Determine process id (#ps aux) and terminate process (#kill –s ) CS423 - cotter23

Running Servers in Linux To keep process active after user logs off, start the process using “nohup” - - no hangup – May be run as local user (used to require root privilege) – #nohup imServer 789 & – Any terminal output sent to a file “nohup.out” To terminate process: – Determine process ID (#ps aux | grep imServer ) => – Terminate process (#kill –s ) CS423 - cotter24

Example Linux Server cs423]$ nohup./imServer & [1] 5500 cs423]$ nohup: ignoring input and appending output to ânohup.outâ cs423]$ ps aux | grep imServer cotterr pts/0 R 09:26 0:11./imServer cotterr pts/0 S+ 09:27 0:00 grep - -color=auto imServer cs423]$ kill -s cs423]$ CS423 - cotter25

Linux System Servers Generally known as Daemon Processes Processes that are expected to have an extended life. Run in the background (not associated with tty) Generally started during system initialization – mail servers, web servers, ftp servers, echo servers, etc. syslog function: – Resource to store error and status messages for daemons, etc. – Currently implemented using rsyslogd. – Configuration file /etc/rsyslog.conf CS423 - cotter26

Daemon Creation Process Call a fork, and close parent – puts process in the background – ensures that process isn’t process group leader. Create a new session – become a session /process group leader – ensure that there is no controlling terminal Change working directory to root – ensure that daemon isn’t running on a partition that can be unmounted CS423 - cotter27

Daemon Creation Process Set file creation mask to 0 – File creation mask controls how the daemon can manipulate files. A mask of 0 ensures that any restrictions of the parent are removed for the daemon Close unneeded file descriptors CS423 - cotter28

Daemon init function include,, int daemon_init(void) { pid_tpid; if ((pid = fork ( )) < 0) return(-1); else if (pid != 0)/* parent*/ exit (0); setsid ( ); chdir(“/”); umask(0); return(0); } CS423 - cotter29

Daemon Processes User Daemons – at command (for one time delayed processes) at [-f file] time [date] [+increment] [command | file]... at -f myfile 6 am Friday at now + 2 days uuclean – crontab command (for repeating functions) crontab -e (-r, -l) – min hr day mon DOW command – * myjob – 30 6 * * 1,3,5 /usr/bin/calendar CS423 - cotter30

Summary Several different factors involved in server design 4 basic types of servers Server concurrency can be real or apparent Linux server simple to run in background CS423 - cotter 31