Guide: Async IO
Enter the labs/lab-11/guides/async/ folder for some implementations of a simple request-reply server in C. Here we have the implementation of a server that computes the n-th fibonacci number. The server serves requests in different ways:
- synchronous server:
server.c - multiprocess server:
mp_server.c - multithreaded server:
mt_server.c
Note: There is no asynchronous C variant, because of the unstable API of libaio and io_uring.
-
Benchmark the synchronous server to have a reference point. Run
./server 2999in one terminal andtime ./client_bench.sh 2999in another.client_bench.shwe’ll run8instances ofclient.pythat make a request.student@os:~/async/support$ time ./client_bench.sh 2000 [...] root: Connected to localhost:2000 root: Sending 30 function(30): 1346269 real 0m1.075s user 0m0.301s sys 0m0.029sThe value you obtain might be different, but you should observe a speed-up when benchmarking the other two solutions.
-
Benchmark the multiprocess and multithreaded alternatives and see which one got the best speed increase. You can obtain more relevant values by tweaking parameters in
client_bench.sh. For example, you could increase the number of clients or the fibonacci value to compute. -
Begin by benchmarking the synchronous server to establish a baseline. Run
./server 2999in one terminal andtime ./client_bench.sh 2999in another. Theclient_bench.shscript will initiate8instances ofclient.py, each making a request. The output might look like this:student@os:~/async/support$ time ./client_bench.sh 2000 [...] root: Connected to localhost:2000 root: Sending 30 function(30): 1346269 real 0m1.075s user 0m0.301s sys 0m0.029sAlthough the actual value may vary, you should observe a noticeable speed-up when testing the other two solutions.
-
Next, benchmark the multiprocess and multithreaded alternatives to determine which offers the best performance improvement. To obtain more meaningful results, adjust parameters in
client_bench.sh, such as increasing the number of clients or the Fibonacci value to compute.
If you’re having difficulties understanding the support code, go through this reading material. If you want to practice this yourself, go through the Async Server task.