Multiservice Servers (TCP, UDP) - ntut.edu.twcmliu/NP/NTUT_NP_F07u/... · Initially, it opens one...
Transcript of Multiservice Servers (TCP, UDP) - ntut.edu.twcmliu/NP/NTUT_NP_F07u/... · Initially, it opens one...
NTUT, TAIWAN 1
Mobile Computing & Software Engineering Lab
Multiservice Servers (TCP, UDP)
Prof. Chuan-Ming LiuComputer Science and Information Engineering
National Taipei University of TechnologyTaipei, TAIWAN
NTUT, TAIWAN 2
Mobile Computing & Software Engineering Lab
Consolidating ServersSame motivations for multiprotocol serversHigher risk to use a single, multiserviceserver, why?Consolidating many services into a single server process reduces
the number of executing processes dramaticallyThe total code required
Most multiservice servers use a single transport protocol
NTUT, TAIWAN 3
Mobile Computing & Software Engineering Lab
Connectionless Multiservice
Server
OS
ApplicationProcess
Master sockets (One for each service
being offered)
NTUT, TAIWAN 4
Mobile Computing & Software Engineering Lab
Connection-Oriented Multiservice
Multiservice server can be programmed to handle some services iteratively and other services concurrentlyConcurrency can be implemented with multiple single-threaded processes or a multi-threaded process
NTUT, TAIWAN 5
Mobile Computing & Software Engineering Lab
Iterative, Connection-Oriented Multiservice
Master
OS
ApplicationProcess
Master sockets (One for each
service offered)
Socket for an individual
connection
NTUT, TAIWAN 6
Mobile Computing & Software Engineering Lab
Concurrent Connection-Oriented Multiservice
Master
OS
ApplicationProcesses(or threads)
Sockets for connection
requests
Sockets for individual
connections
slave 1 slave n
NTUT, TAIWAN 7
Mobile Computing & Software Engineering Lab
Single-thread, MultiserviceIt is also possible, but uncommon, to implement multiservice servers with a single thread of executionMainly on connection-oriented style
NTUT, TAIWAN 8
Mobile Computing & Software Engineering Lab
Invoking Separate Programs
Main flaw for multiservice servers – inflexibilityChanging small piece of code needs to recompile the entire server – time consumingStopping the server to recompile bothers clients
How to overcome this?Break a server into independent parts Then, handle each part independentlyReplace the original code by execve
NTUT, TAIWAN 9
Mobile Computing & Software Engineering Lab
Multiprocess Multiservice (TCP)
Master
OS
ApplicationProcesses
Master sockets (One for each
service offered)
Sockets for individual slave
connections
slave1 slaven
prog1 progn execve( ) used
fork( )
NTUT, TAIWAN 10
Mobile Computing & Software Engineering Lab
Invoking Separate ProgramsIn a mulitservice server, the execve( )system call makes it possible to separate the code that handles an individual service from the code that manages initial requests from clients
NTUT, TAIWAN 11
Mobile Computing & Software Engineering Lab
Multi-service Multi-protocol
It is possible to design a multi-service server having multi-protocol as described before.Super server: multi-service, multi-protocol server
Initially, it opens one or two sockets for each serviceMaster sockets correspond to UDP or TCPUse select system call to wait for any socket to become readyIf a UDP socket is ready, read, process and replyIf a TCP socket is ready, handle the connection directly (iteratively) or create a process to handle it (concurrently)
NTUT, TAIWAN 12
Mobile Computing & Software Engineering Lab
Multiservice Server – Example Example, superd.cThe CHARGEN service
Tests client softwareGenerates an infinite sequence of characters and sends it to the client
For a UDP socket, the server calls the service handler directlyFor a TCP socket, the server calls the service handler indirectly through procedure doTCP
NTUT, TAIWAN 13
Mobile Computing & Software Engineering Lab
Server ConfigurationSuper servers are often configurable – set of services can be changed without recompiling source codeUsually, the configuration information is stored in a fileTwo types:
Static: occurs when the server startsDynamic: occurs while a super server is running
NTUT, TAIWAN 14
Mobile Computing & Software Engineering Lab
Server ConfigurationHow to inform a server that reconfiguration is needed?
Depends on the OS, for example, in LINUX one can use signal mechanism used for inter-process communication
A well-designed super server handles reconfiguration gracefullyDynamically changing configuration is more flexible
NTUT, TAIWAN 15
Mobile Computing & Software Engineering Lab
Most Unix systems provide a “SuperServer”that solves the problem:
executes the startup code required by a bunch of servers.Waits for incoming requests destined for the same bunch of servers.When a request arrives - starts up the right server and gives it the request.
NTUT, TAIWAN 16
Mobile Computing & Software Engineering Lab
Super Server, inetdOn most UNIX systems, including LINUX, the super server, inetd, handles a large set of servicesMotivation for inetd – Less consumption on resourcesDynamically configurable
Newer versions of Linux replace the inetd with xinetd
NTUT, TAIWAN 17
Mobile Computing & Software Engineering Lab
inetd childreninetd forks a child that executes the real server program and handles the request and exits.The inetd process remains running after the forkThe child process closes all unnecessary sockets.inetd uses the wait status to determine how to proceed after starting a service
NTUT, TAIWAN 18
Mobile Computing & Software Engineering Lab
/etc/inetd.conf
inetd reads a configuration file that lists all the services it should handle. inetd creates a socket for each listed service, and adds the socket to a fd_setgiven to select().
NTUT, TAIWAN 19
Mobile Computing & Software Engineering Lab
inetd service specificationFor each service, inetd needs to know:
the port number and transport protocolwait/nowait flag.login name the process should run as.pathname of real server program.command line arguments to server program.
NTUT, TAIWAN 20
Mobile Computing & Software Engineering Lab
# comments start with #echo stream tcp nowait root internalecho dgram udp wait root internalchargen stream tcp nowait root internalchargen dgram udp wait root internalftp stream tcp nowait root /usr/sbin/ftpd ftpd -ltelnet stream tcp nowait root /usr/sbin/telnetd telnetdfinger stream tcp nowait root /usr/sbin/fingerd fingerd# Authenticationauth stream tcp nowait nobody /usr/sbin/in.identd
in.identd -l -e -o# TFTPtftp dgram udp wait root /usr/sbin/tftpd tftpd -s
/tftpboot
example /etc/inetd.conf
NTUT, TAIWAN 21
Mobile Computing & Software Engineering Lab
Wait/nowaitSpecifying WAIT means that inetd should not look for new clients for the service until the child (the real server) has terminated.TCP servers usually specify nowait
this means inetd can start multiple copies of the TCP server program - providing concurrency!
NTUT, TAIWAN 22
Mobile Computing & Software Engineering Lab
UDP & wait/nowaitMost UDP services run with inetd told to wait until the child server has died. What would happen if:
inetd did not wait for a UDP server to die.inetd gets a time slice before the real server reads the request datagram?
NTUT, TAIWAN 23
Mobile Computing & Software Engineering Lab
Super inetdSome versions of inetd have server code to handle simple services such as
echo server, daytime server, chargen server,…
NTUT, TAIWAN 24
Mobile Computing & Software Engineering Lab
xinetdxinetd can be used to
Provide access only to particular hostsDeny access to particular hostsProvide access to a service at a certain timeetc…
The configure file is /etc/xinetd.confNote: xinetd.conf calls separate files in the directory /etc/xinetd.d
NTUT, TAIWAN 25
Mobile Computing & Software Engineering Lab
Server Variations
Super server (with a configuration file)Multiple services, multiple protocols
Concurrent, separate program
Multiple services, single protocolConcurrent, multiple threads or processes
(common)Single service, multiple protocolsMultiple services, single protocolMultiple services, multiple protocols
Concurrent, single thread
(unusual)Single service, multiple protocolsMultiple services, single protocol
Iterative
DescriptionType