A demo project to present a concurrency features of the Rust programming language.
The HTTP server is based on the 'The Rust Programming Language' book and has been adapted for demonstration needs.
Project consists of two independent executable i.e. server and client application, that communicate with each other using HTTP protocol.
The HTTP server awaits for HTTP request and sends a simple HTML response which can be rendered by the browser.
If client's request contains integer values, the server, in the background, will sum these values, and the result is included in the response.
Empty or non-integer request will be treated as value of 1
.
Sends HTTP requests with some abstract integer data, which can represent e.g. sensor measurement. The value is currently hardcoded but any other value can be handled by the server as well.
The following concurrency issues are demonstrated in this project.
As explained in 'The Rust Programming Language' book, the server is a multi-threaded one, with a thread pool capable of handling 1024 client request in parallel.
Server is processing request data in the background in a non-blocking way, thanks to Multi-producer, single-consumer FIFO message queue (MPSC).
Threads handling HTTP request are streaming data to the worker which is processing them, and worker is sending processed data back to the main thread.
[Request 1] --\
[Request 2] ---> [MPSC] -> [Worker] -> [Main Thread]
[Request 3] --/
Issue the following commands to start the server:
cd server
cargo run
Issue the following commands to send one request:
cd client
cargo run
To loop client, issue the following command:
while true; do client/target/debug/client; done
Browser can also be used to send request, by loading the following page http://127.0.0.1:7878.
Issue the following command to send a request with a value of 13:
curl http://127.0.0.1:7878/13