Concurrent programming
Before you start, make sure you have completed the previous lab. You can also use the code from the tp2_base branch from the git repository:
- git clone -b tp2_base https://gitlab.inf.telecom-sudparis.eu/csc4508/csc4508_facebook.git csc4508_tp2
- or git checkout tp2_base
pool of threads
During the previous lab, we parallelized the server by creating a thread for each connection. This solution wastes resources unnecessarily.
To avoid this waste, we propose to create, during the server initialization, a pool of threads. So that when a new connection is detected, its processing is delegated to one of the previously created threads.
What is the synchronization pattern to be implemented here?
It is a producer-consumer.
- The main thread produces requests to be processed ;
- The threads from the pool consume requests .
Implement this mechanism and evaluate its performance.
To evaluate the performance of the server, you can use the ab tool (available in the apache2-utils package on Debian) which measures the response time of a web server. For example, with the following command:
Here, ab sends 100,000 requests to the address http://localhost:8080/ with a concurrency of 4.
Among the functionalities implemented by the server (add_user, list_users, etc.), some modify data structures, and others just consult them.
What is the synchronization pattern to be implemented here?
Implement this synchronization pattern and evaluate its performance.
data persistence
Currently, the data (users, messages, etc.) are destroyed when the server ends. This obliges to recreate all users and their interactions each time the server restarts.
An IPC shared memory area allows persistence of data: as long as the IPC object is not destroyed, the data exists.
Use a shared memory segment to keep the data data (users, messages, etc.) when restarting the server.