Skip to content

Commit 577df03

Browse files
authored
Update README.md
1 parent 26d15af commit 577df03

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Proxy Server
2+
23
Proxy is a simple concurrent HTTP proxy server that caches recently-requested web objects.
34

45
It's an application for learning about ***Socket Programming*** and ***Concurrent Programming***.
@@ -24,6 +25,7 @@ It's an application for learning about ***Socket Programming*** and ***Concurren
2425

2526

2627
## Overview
28+
2729
A web proxy is a program that acts as a middleman between a Web browser and an end server.
2830
- Instead of contacting the end server directly to get a Web page, the browser contacts the proxy, which forwards the request on to the end server. When the end server replies to the proxy, the proxy sends the reply on to the browser.
2931
- It can deal with multiple concurrent connections using multi-threading.
@@ -34,22 +36,27 @@ A web proxy is a program that acts as a middleman between a Web browser and an e
3436

3537
It has the following detailed behavior:
3638
- **Set up** the proxy to accept incoming connections:
37-
1) Proxy creates a listening descriptor that is ready to receive connection requests on port ***`port`*** by calling ***`Open_listenfd()`*** funciton defined in **`socket.c`** file.
39+
40+
1. Proxy creates a listening descriptor that is ready to receive connection requests on port ***`port`*** by calling ***`Open_listenfd()`*** funciton defined in **`socket.c`** file.
3841

3942
- **Set up** the proxy to deal with multiple concurrent connections using **prethreading** technique:
40-
1) After initializing buffer ***`sbuf`*** declared in **`sbuf.h`** file, the main thread creates the set of worker threads by calling ***`Pthread_create()`*** defined in **`thread.c`** file.
41-
2) Main thread then enters an infinite loop, waiting for connection requests using ***`Accept()`*** function defined in **`socket.c`** file.
42-
3) It then inserts the resulting connected descriptors in ***`sbuf`***.
43-
4) Each worker thread waits until it is able to remove a connected descriptor from the buffer and then calls the ***`serve_client()`*** function to serve the client.
43+
44+
1. After initializing buffer ***`sbuf`*** declared in **`sbuf.h`** file, the main thread creates the set of worker threads by calling ***`Pthread_create()`*** defined in **`thread.c`** file.
45+
2. Main thread then enters an infinite loop, waiting for connection requests using ***`Accept()`*** function defined in **`socket.c`** file.
46+
3. It then inserts the resulting connected descriptors in ***`sbuf`***.
47+
4. Each worker thread waits until it is able to remove a connected descriptor from the buffer and then calls the ***`serve_client()`*** function to serve the client.
48+
4449
- **Run** ***`serve_client()`*** routine:
45-
1) Read and parse the _HTTP_ request sent from the client by calling ***`read_HTTP_request()`*** function defined in **`serve.c`** file.
46-
2) using ***`hash()`*** function defined in **`cache.c`** file, generate ***`HTTP_request_hash`*** that will be used to check if the cache contains the requested web object.
47-
3) If the object is cached then read the object out of the cache rather than communicating again with the server by calling ***`service_from_cache()`*** function defined in **`service.c`** file.
48-
4) Otherwise, using ***`service_from_server()`*** function, Try to connect the server then send it the ***`parsed_request`***, read its response, write it back to the client, and save it in an internal buffer for possible caching.
49-
5) If ***`object_size`*** is less than ***`MAX_OBJECT_SIZE`*** write the object in a suitable cahce line.
50+
51+
1. Read and parse the _HTTP_ request sent from the client by calling ***`read_HTTP_request()`*** function defined in **`serve.c`** file.
52+
2. using ***`hash()`*** function defined in **`cache.c`** file, generate ***`HTTP_request_hash`*** that will be used to check if the cache contains the requested web object.
53+
3. If the object is cached then read the object out of the cache rather than communicating again with the server by calling ***`service_from_cache()`*** function defined in **`service.c`** file.
54+
4. Otherwise, using ***`service_from_server()`*** function, Try to connect the server then send it the ***`parsed_request`***, read its response, write it back to the client, and save it in an internal buffer for possible caching.
55+
5. If ***`object_size`*** is less than ***`MAX_OBJECT_SIZE`*** write the object in a suitable cahce line.
5056

5157

5258
## How does proxy deal with concurrent requests?
59+
5360
- We incur non-trivial cost of creating a new thread for each new client.
5461
- A proxy based on *prethreading* tries to reduce this overhead by using the **producer-consumer** model shown in the figure.
5562
- The proxy consists of a ***main thread*** and a set of ***worker threads***, the main thread repeatedly accepts connection requests from clients and places the resulting connected descriptors in a bounded buffer.
@@ -59,6 +66,7 @@ It has the following detailed behavior:
5966

6067

6168
## How does proxy synchronize accesses to cache?
69+
6270
- Accesses to the cache must be thread-safe, and free of race conditions, So as a matter of fact we have these special requirements:
6371
1. Multiple threads must be able to simultaneously read from the cache.
6472
2. No thread can write to specific object while another thread is reading it.

0 commit comments

Comments
 (0)