Project 3: Multi-threaded Web Server

Assignment Day February 08, 2018 (Thursday night)
Due Date February 27, 2018 (Tue)

Name the directory you submit P3 and submit code to csx730.

A directory (and a ZIP file) containing a single server webserver webserver.c is available in here, and as a zip file here. This server is modified version of a webserver written originally for the Sanos operating system available here:

http://www.jbox.dk/sanos/webserver.htm

This server also runs on Linux (and therefore on the nike cluster), and on Mac OS X.

A single threaded web client to test your server is available here, modified from (http://coding.debuntu.org - page with original client not available anymore).

Overview

In this project, you will tackle mult-threading. Your job design & implement an efficient multithreaded webserver given working serial (single-thrreaded) webserver.

Essentially you will convert this server into a multi-threaded architecture.

The code that deals with sockets or the HTTP protocol, is provided and will need minor modifications - if any modifications.

Minimal Design: Thread-pools

A central problem of a single-threaded web server is scalability. It cannot scale up to large numbers of clients. To address this problem, you will convert the web server into a multi-threaded model. To minimize unnecessary overhead such as thread creation or termination, you will design and implement a thread-pool model.

Your server maintains thread pool. When the server launches, it creates a “thread_control” thread.

The control thread creates [N] worker threads and one listener thread. Only the listener thread listens for client requests via client connections. When such request (or connection) arrives, the listener thread accepts it and places it into a request data structure (e.g., a linked list). All threads have access to pull the data structure.

Available worker threads pull requests from the data structure, processes the requests from the connection, produces a response and sends it back to the client.

You will need to carefully use synchronization methods to avoid concurrency problems such as race conditions or deadlocks (all threads blocking and waiting for each other).

  1. Server Launches
  2. Server creates: thread_control thread.
  3. thread_control thread creates:
    • N worker threads
    • 1 listener thread
    • Data Structure called requests.
  4. worker_thread pulls requests from the data structure called requests.
    • process the requests, produces a responce, and sends it back to the client.
  5. listener_thread listens for client requests via connections, and inserts the requests into a data structure called requests.

The control thread will monitor the status of the child threads, and if one or more worker threads terminate (e.g., crash), the control thread spawns another worker thread to maintain [N] worker thread in the pool. You can use “pthread_tryjoin_np” for non-blocking join.

 

You will modify the skeleton / or template webserver_multi.c.

You will need to write a report on the performance of your webserver.

Check piazza for details on what is expeced in the report.