Homework 11 Solved

22C:116, Fall 1999

Douglas W. Jones

  1. There was a mistake in the numbering of the questions.
  2. Part A: The web server design that was given offers poor performance because it forces each request for web service to be handled in strict sequence, reading and returning an entire file to one client before starting to find a file needed by another client. As a result, no disk scheduling is possible, and if the server has multiple disks, there can be no overlap of seek time on one disk with data transfer on another.

    Part B: Here is a redesign of the web server using appropriate thread primitives.

            repeat
               await request from client c for file f
    	   create a new thread to do the following
                 establish connection to c
                 open f
                 repeat
                   for each sector of f
                   send the sector over the connection to c
                 until all sectors sent
                 terminate connection to c
               end of new thread
            forever
    

    Part C: If the above design is deluged with thousands of requests from far away users, the time it takes to begin service of one user request may be reasonably fast, but there will be many threads competing to do read operations, so the time to read and transmit the file entire file may be unreasonably slow.

    There is probably an optimal number of threads that will lead to the best service, probably a number of threads that is a small integer multiple of the number of disk drives. If we limit the number of threads to this number, a high traffic server would delay its reply with the first requested sector, but it would deliver the successive sectors of each file quite quickly.

  3. A Question: Question 4 on page 547 of the text asked why pointers to global variables might be preferred over direct global addressing in a multithreaded environment. First, global has multiple meanings. Is a global variable global to the entire multithreaded application, or are we speaking of variables global to the collection of functions that make up one thread. Languages like C have no provisions for the latter, so what we need to do is allocate a record, object or equivalent structure to hold the global state of a thread and pass a pointer to this to every function called by that thread that must access "global-to-the-thread" variables.

    Second, in multithreaded systems where there are multiple processes acting as virtual CPUs to run threads from one shared application, the only shared variables are typically in a shared heap. The static variables of the code are typically on the base of the stack, in private variables of each process. In this context, each thread runs on a stack in the shared heap, so the local variables of a thread are properly shared, but the global variables are not shared! So, to share variables that are logically global, they must be allocated from the shared heap and accessed by pointer.

  4. Part A: In choosing between the following alternatives: Moving the process to the machine that has the file, moving the file to the machine that has the process, or moving just the bytes required by the read and write operations requested by that process, the independent variables we must consider are:

    The size of the process representation that must be moved

    The size of the file itself

    The size of the part of the file that is to be accessed

    Part B: A small process that acceses an entire large file should be moved to the machine that has that file. A small file that is accessed by a large application should be moved to the machine holding that application. If the part of the file that is to be accessed is smaller than both the file and the process that accesses the file, only that part should be moved, and neither the file nor the process should migrate.