SDSU CS 596 Client-Server Programming
Server Types

[To Lecture Notes Index]
San Diego State University -- This page last updated February 29, 1996

Contents of Server Types Lecture

  1. Server Stuff
    1. Simple Algorithm (doserver)
    2. Iterative Server
    3. Iterative Server (cont.)
    4. Concurrent Server
    5. Concurrency using inetd
    6. Concurrency built into the server
      1. OS Concurrency
      2. Language Concurrency (threads)
      3. Emulating Concurrency
  2. Comparing Server Types
    1. Server types: Efficiency
    2. Server types: Resource usage
    3. Server types: Platform limitations
    4. Server types: Portability

Server Stuff


So far we have seen:


Next step: Designing and implementing network Servers.


Reading material:

Comer chapt 8: Algorithms And Issues In Server Software Design


Simple Algorithm (doserver)



In its most simplistic form, a server will have to perform the following algorithm:




What is wrong with this?


Iterative Server


Answer:

Request processing blocks any other connections


Example:

Hypothetical server asks for an integer n and replies with a list of the all prime numbers with n digits.

User one connects and enters 500
User two attempts to connect, but the server will be busy for a LONG time.

Solutions:

Multiple connections need to be accepted concurrently.


Iterative Server (cont.)


In some cases it may be valid to use a simple iterative server.

Rule of thumb:

If the time required to service a complete server request can be limited to a very short time, an iterative server can be used.


From this rule it follows that connection oriented (TCP) servers should never be of the iterative type.

Why?


Concurrent Server


A concurrent server can handle multiple requests concurrently.

Most TCP servers are of this kind.

Examples:



How is this done?

Two ways:


Concurrency using inetd


As we have seen before, the inetd configuration file looks like this:

<service_name> <socket_type> <proto> <flags> <user> <server_pathname> <args>

and an example telnet service entry:

telnet stream tcp nowait root /usr/sbin/in.telnetd in.telnetd

The nowait here means that inetd should NOT wait for the server program (in.telnetd) to finish before more requests can be handled.


Concurrency built into the server


Standalone servers have several options.


Every one of these is a valid solution.

The server environment may not allow you to implement all of these.

For example:


OS Concurrency


Under Unix, the fork() system call is used to create new processes.

The fork() call creates a copy of the current process. It inherits many things including open file descriptors.

Terminology:
A parent forks to produce a child.

Basic algorithm:

Server creates an accepting socket.
repeat forever
{
    Wait for new client request.
    create a child (fork)
         the child will start dealing
         with the client.
}


Language Concurrency (threads)


Concurrency in the implementation language is normally in the form of threads or something similar.

Threads can also be supported by the OS:


Difference between threads and processes:


The algorithm is mostly the same as with concurrent processes.

Since threads share the same address space, Sockets can easily be passed from one thread to another.


Emulating Concurrency

(single process concurrent server)

Concurrency can be achieved with special OS support.

The key to this method is the use of non-blocking I/O operations.

For example, Winsock (MS-Windows networking library) uses message passing to notify routines that I/O operations have completed.

Unix has the select() system call and have a non-blocking flag for socket operations.

Basic algorithm:

Create accepting socket.
repeat forever
{
    wait for ANY I/O operation.
    depending on the type of operation, perform actions.
}


Comparing Server Types


Why worry about the different server types and always use the same one?

Issues:


Server types: Efficiency


For services that are used frequently (meaning many connections are made), creating a new process may be too slow.

Examples:


Other services are not used very frequently:



Other issues:

Cost of development.
Time to initiate service vs. time to complete request.


Server types: Resource usage


System resources:



A process (and to a lesser extend, a thread) take up system resources.

Normally there are also per-process or per-thread resource limits.

A single process is going to use up fewer resources, but may depleet some of the faster.


Other import resource:


Server types: Platform limitations


The server platform can limit the types:


Server types: Portability


If a server needs to be ported to several platforms, only a common subset of features can be used.

Example:

Both Solaris and Windows NT have threads, but they are not compatible.


Fortunately this is not an issue with Java since it is platform independent.