To run the server, use gcc main.c. Then, use ./a.out . There description can be found below or in describe.pdf
#Design
-
Parent process starts up the server and creates a process pool with each child calling accept() call.
-
Server should be self-regulated as per the incoming traffic. Parent should regulate the process pool according to the parameters specified: MinSpareServers, MaxSpareServers. These parameters are specified as command line arguments to the server.
-
The MaxSpareServers is the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes.
-
The MinSpareServers is the desired minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than MinSpareServers idle, then the parent process creates new children: It will spawn one, wait a second, then spawn two, wait a second, then spawn four, and it will continue exponentially until it is spawning 32 children per second. It will stop whenever it satisfies the MinSpareServers.
-
Server should recycle the child once it finishes handling MaxRequestsPerChild number of connections. This parameter is also taken as command line parameter.
-
Child waits over listening socket. Whenever it accepts a connection, it prints its pid, client's ip and port. Child receives the HTTP request, sleeps for 1 second, and sends a dummy reply.
-
Whenever a parent makes a change to the process-pool, it prints the number of children in process pool, number of clients being handled, action being taken, post-action status.
-
Use UNIX Domain sockets for any parent-child communication.
-
By sending Ctrl-c signal, parent process prints number of children currently active, and for each child how many clients it has handled.
-
Server takes care of zombie processes.
-
Further design explanation and features can be found in the describe.pdf file.
#Testing
- ab tool was used for testing the server. Running server is tested using the cmd - "ab -n 3 -c 3 http://127.0.0.1:4243/", where -n is Number of requests to perform and -c is Number of multiple requests to make at a time. 127.0.0.1 is the home IP address and 4243 is the port used by the server.
- ab tool only provides iterative request features, i.e. only 1 request per time. To test the capability of server handling multiple requests at a time, we use test.c, a program that generates multiple concurrent requests.