billgewrgoulas / Multithreaded-Server

Implementation of a multithreaded server that allows multiple users to make requests at the same time. Built for the course Operating Systems @CS.UOI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multithreaded Server using pthreads and sockets.

Implementation of a multithreaded server that allows multiple users to make requests at the same time. Each user can request access to the database and the request can be PUT or GET. The implementation makes use of the reader/writter logic where only one writter can modify the database or multiple readers can access it and read data at the same time, as well as the producer/consumer logic to synchronize the incoming requests. Also the implementation gives priority to readers. For the tests, a multithreaded client is used to establish a TCP Connection over the server and start feeding requests.

Explanation

Consumers - Producers

  • Producer Thread - Main thread that awaits for requests from a client through a TCP connection. Produces a request descriptor for every incoming request and awaits if the buffer is full or appends it and notifies a consumer thread to serve it acordingly.
  • Consumer Threads - Multiple threads that are responsible for extracting and serving the requests from the buffer in parallel if the buffer is not empty. Depending on the request descriptor a consumer thread can be either a reader or a writter.
  • Buffer - Circular FIFO Queue of finite size. Just like all the global resources it must be protected by mutual exclusion when modified.

Readers - Writers (Priority to Readers)

  • Readers – Readers are those processes/users which only read the data.
  • Writers – Writers are those processes which also write, that is, they change the data.
  • It is allowed for 2 or more readers to access shared data, simultaneously as they are not making any change and even after the reading the database will remain unchanged.
  • But if one writer(Say w1) is writing then it should lock and no other writer or reader can access the database until w1 has finished writing.

Multithreaded Client

  • To test the server we will use a multithreaded client. Each thread will establish a TCP connection in parallel and make a random request (PUT or Get) to the server.

Custom Signal Handler CTRL-Z

  • The signal handler is responsible to block the default handler with sigmask and assign a custom method to handle CTRL-Z.
  • When the signal arrives the servers outputs the statistics then awakes and terminates all threads safely using global flag variables and pthread_join()

DataBase(kissdb)

  • For our database we will use KISSDB created by Adam Ierymenko.
  • KISSDB is about the simplest key/value store you'll ever see, anywhere. It's written in plain vanilla C using only the standard string and FILE I/O functions, and should port to just about anything with a disk or something that acts like one.

Usage

Run the server with ./server then in a new terminal do ./client . You can also use the custom signal handler with CTRL-Z to terminate the server and see the stats for various number of consumer threads and queue size.

About

Implementation of a multithreaded server that allows multiple users to make requests at the same time. Built for the course Operating Systems @CS.UOI.

License:MIT License


Languages

Language:C 99.0%Language:Makefile 1.0%