CSIE,NTUT,Taiwan1
Multiservice
Servers
Chuan-Ming Liu
Computer Science and Information Engineering
Spring 2004,NTUT
TAIWAN
CSIE,NTUT,Taiwan2
Consolidating Servers
Same motivations for multiprotocol servers
Higher risk to use a single,multiservice
server,why?
Consolidating many services into a single
server process reduces
the number of executing processes dramatically
The total code required
Most multiservice servers use a single
transport protocol
CSIE,NTUT,Taiwan3
Connectionless Multiservice
Server
OS
Application
Process
Master sockets
(One for each service
being offered)
CSIE,NTUT,Taiwan4
Connection-Oriented
Multiservice
Multiservice server can be programmed
to handle some services iteratively and
other services concurrently
Concurrency can be implemented with
multiple single-threaded processes or a
multi-threaded process
CSIE,NTUT,Taiwan5
Iterative,Connection-
Oriented Multiservice
Master
OS
Application
Process
Master sockets
(One for each
service offered)
Sockets for
a TCP
connections
CSIE,NTUT,Taiwan6
Concurrent Connection-
Oriented Multiservice
Master
OS
Application
Processes
(or threads)
Socket for
connection
requests
Sockets for
individual
connections
slave 1 slave n
CSIE,NTUT,Taiwan7
Single-thread,Multiservice
It is also possible,but uncommon,to
implement multiservice servers with a
single thread of execution
Mainly on connection-oriented style
CSIE,NTUT,Taiwan8
Invoking Separate Programs
Main flaw for multiservice servers –
inflexibility
Changing small piece of code needs to recompile
the entire server – time consuming
Stopping the server to recompile bothers clients
How to overcome this?
Break a server into independent parts
Then,handle each part independently
,overloading” implemented by execve
CSIE,NTUT,Taiwan9
Multiprocess Multiservice (TCP)
Master
OS
Application
Processes
Master sockets
(One for each
service offered)
Sockets for
individual slave
connections
slave 1 slave n
prog 1 prog n execve( ) used
fork( )
CSIE,NTUT,Taiwan10
Invoking Separate Programs
In 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
CSIE,NTUT,Taiwan11
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 service
Master sockets correspond to UDP or TCP
Use select system call to wait for any socket to become ready
If a UDP socket is ready,read,process and reply
If a TCP socket is ready,handle the connection directly
(iteratively) or create a process to handle it (concurrently)
CSIE,NTUT,Taiwan12
Multiservice Server – Example
Example,superd.c
The CHARGEN service
Tests client software
Generates an infinite sequence of characters
and sends it to the client
For a UDP socket,the server calls the
service handler directly
For a TCP socket,the server calls the
service handler indirectly through procedure
doTCP
CSIE,NTUT,Taiwan13
Server Configuration
Super servers are often configurable –
set of services can be changed without
recompiling source code
Usually,the configuration information
is stored in a file
Two types,
Static,occurs when the server starts
Dynamic,occurs while a super server is
running
CSIE,NTUT,Taiwan14
Server Configuration
How 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 gracefully
Dynamically changing configuration is
more flexible
CSIE,NTUT,Taiwan15
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.
CSIE,NTUT,Taiwan16
Super Server,inetd
On most UNIX systems,including
LINUX,the super server,inetd,
handles a large set of services
Motivation for inetd – Less
consumption on resources
Dynamically configurable
Newer versions of Linux replace the inetd
with xinetd
CSIE,NTUT,Taiwan17
inetd children
inetd forks a child that executes the real
server program and handles the request
and exits.
The inetd process remains running after
the fork
The child process closes all unnecessary
sockets.
inetd uses the wait status to determine
how to proceed after starting a service
CSIE,NTUT,Taiwan18
/etc/inetd.conf
inetdreads 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().
CSIE,NTUT,Taiwan19
inetd service specification
For each service,inetd needs to know:
the port number and transport protocol
wait/nowait flag.
login name the process should run as.
pathname of real server program.
command line arguments to server
program.
CSIE,NTUT,Taiwan20
# comments start with #
echo stream tcp nowait root internal
echo dgram udp wait root internal
chargen stream tcp nowait root internal
chargen dgram udp wait root internal
ftp stream tcp nowait root /usr/sbin/ftpd ftpd -l
telnet stream tcp nowait root /usr/sbin/telnetd telnetd
finger stream tcp nowait root /usr/sbin/fingerd fingerd
# Authentication
auth stream tcp nowait nobody /usr/sbin/in.identd
in.identd -l -e -o
# TFTP
tftp dgram udp wait root /usr/sbin/tftpd tftpd -s
/tftpboot
example
/etc/inetd.conf
CSIE,NTUT,Taiwan21
Wait/nowait
Specifying 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!
CSIE,NTUT,Taiwan22
TCP and wait/nowait
TCP servers usually specify nowait.
This means inetd can start multiple
copies of the TCP server program -
providing concurrency!
CSIE,NTUT,Taiwan23
UDP & wait/nowait
Most 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?
CSIE,NTUT,Taiwan24
Super inetd
Some versions of inetd have server
code to handle simple services such as
echo server,
daytime server,
chargen server,

CSIE,NTUT,Taiwan25
xinetd
xinetd can be used to
Provide access only to particular hosts
Deny access to particular hosts
Provide access to a service at a certain time
etc…
The configure file is /etc/xinetd.conf
Note,xinetd.conf calls separate files in
the directory /etc/xinetd.d
CSIE,NTUT,Taiwan26
Server Variations
Type Description
Iterative (unusual)Single service,multiple protocols
Multiple services,single protocol
Concurrent,single thread (common)Single service,multiple protocols
Multiple services,single protocol
Multiple services,multiple protocols
Concurrent,multiple threads
or processes
Multiple services,single protocol
Concurrent,separate
program
Super server (with a configuration file)
Multiple services,multiple protocols