Multi-Threaded Proxy Server Guide

0% found this document useful (0 votes)
368 views14 pages
In computer networks, a proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requestin…

Uploaded by

proxiesforrent
  • Introduction
  • Step 1: Implement a barebones proxy
  • Step 2: Make the proxy multi-threaded
  • Step 3: Add a cache to the proxy
  • Step 4: Deploy the proxy on EC2
  • Grading Policy

Multi threaded proxy

In computer networks, a proxy server is a server that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource available from a different server and the proxy server evaluates the request as a way to simplify and control its complexity. Proxies were invented to add structure and encapsulation to distributed systems. Today, most proxies are web proxies, facilitating access to content on the World Wide Web.

Step 1: Implement a barebones proxy

Opens a TCP server socket to listen for TCP connections on a particular port. When a new connection is setup, the proxy reads in a HTTP request; yourcode needs to be compatible with HTTP GET requests sent by the curl HTTP client.

The cheap proxy should then pass on that HTTP request to the relevant webserver, download the data received, and send it back to the client on the TCP connection that the client had established. You need to ensure that you can handle interleaving of requests from multiple clients by maintaining sucient state so that you return a response received from a webserver back to the correct client.

Rather than constantly poll sockets to receive data, you should implement network I/O code using the select call. Also, make sure to handle all errors so that your implementation is robust.

Step 2: Make the proxy multithreaded

To improve the throughput oered, make your paid proxy multi-threaded. The proxy would work in the same way as above, except that whenever data is to be received, a new thread is spawned to do so. However, you should limit the number of threads in your code to at most 20, rather than let the number of threads grow unbounded.

Step 3: Add a cache to the proxy

To further improve throughput, add a cache to your cheap proxy server. At any given time, the cache should contain at most 10 MB of data. To evict data from the cache when there is a cache miss, implement the LeastRecently-Used (LRU) cache replacement policy, i.e., always insert into the cache the most recently accessed object and to incorporate it into the cache, evict the appropriate number of least recently used objects from the cache. Ensure that reads from and writes to your cache are thread-safe.

Step 4: Deploy the proxy on EC2

Requirements and Deliverables

All your code must be written in C. Network I/O should use the select, recv, and send calls. Use the pthread library for threading and inter-thread synchronization. The following two deliverables are expected at the end of this project, both due before class on 31st January 2011.

Deploy your proxy on EC2 and email me the address at which your proxy is accessible. The address expected is of the format hostname:port or IPAddress:port. I will then evaluate your implementation with my test suite, which will fetch web pages via your proxy. Email me an archive that contains all your source code.

Grading policy

This project is worth 20 points. 10 points: I will go over your source code to ensure your implementation of (a) select-based socket programming, (b) thread pool, and (c) thread-safe cache look correct.

10 points: I will fetch web pages via your best paid proxy service using the curl HTTP client. Your proxy must be robust enough to handle web requests to arbitrary web sites. The submission that yields the maximum throughput will be granted 10 points. The number of points awarded to all others will be in proportion to the fraction of this maximum throughput their proxy oers.

Thanking you.. For more info log on too.. [Link]

Common questions

Powered by AI

Deploying a proxy server on AWS EC2 involves setting up an instance, configuring it to run the proxy server code, and ensuring it is accessible from the internet. First, after writing the proxy server code in C and ensuring all network I/O and threading are correctly implemented using select, recv, send, and pthreads, the server is deployed by starting an EC2 instance. It's essential to configure security groups to allow traffic on the server's target port. Once the proxy is running, its address in the format 'hostname:port' or 'IPAddress:port' should be shared with evaluators, as specified for grading purposes .

Select-based socket programming contributes to error handling and robustness by allowing the server to efficiently handle multiple file descriptors within a single thread, detecting any sockets that have encountered errors, are ready for reading, or have closed. This non-blocking I/O model ensures the server can promptly respond to network errors or disconnections without crashing or hanging. By using 'select', the proxy can be designed to check for errors and handle them appropriately, such as retrying the connection or closing it gracefully, ensuring the system remains robust under adverse network conditions .

Challenges in using a thread pool for the proxy server implementation include contention and synchronization issues, where multiple threads may try to access shared resources simultaneously leading to race conditions or deadlocks. These issues can be mitigated by implementing thread-safe mechanisms such as mutexes or semaphores to synchronize access to shared resources. Moreover, the design should avoid creating too many threads, which can lead to context switching overheads and excessive memory usage. The implementation limits the thread count to 20 to ensure resource utilization remains efficient .

Using the 'select' system call in constructing the proxy server's network I/O operations is significant because it allows the server to monitor multiple file descriptors to see if they have data available for reading or writing. This is crucial for constructing an efficient I/O loop that can handle multiple simultaneous connections without blocking, thus enabling the server to respond to multiple requests as they come in, rather than having to wait for each one to complete sequentially. This is particularly useful in a multi-threaded environment where maximizing the I/O efficiency can lead to better overall system throughput .

Limiting the cache size to 10 MB impacts the proxy server's performance by constraining the amount of data it can store for quick access. While this limitation helps manage memory resources efficiently and ensures that the cache does not grow excessively, it can also lead to more frequent cache evictions for popular or large resources, potentially increasing retrieval time for requests that miss the cache. This trade-off requires careful management of resource access patterns and the effectiveness of the LRU caching mechanism to minimize performance degradation due to cache misses .

A multi-threaded proxy server offers improved throughput as it can handle multiple client requests concurrently by delegating each request to a separate thread. This allows the server to utilize system resources more efficiently and provide faster response times, especially when processing requests in parallel, as opposed to a single-threaded server that processes requests sequentially. The implementation described uses a limit of 20 threads to prevent resource exhaustion, thus balancing concurrency and resource management .

Implementing a cache using a Least-Recently-Used (LRU) policy enhances proxy server performance by keeping the most frequently requested data readily accessible, reducing the need to repeatedly fetch the same resources from external servers. This optimizes data retrieval time and minimizes network latency for subsequent similar requests. The LRU policy ensures that when the cache reaches its capacity, the least recently accessed data is evicted to make room for new data, maintaining efficient cache utilization .

In a multi-threaded proxy server, reads and writes to the cache must be thread-safe to prevent data corruption and inconsistencies that can occur when multiple threads simultaneously access and modify cache data. Thread safety ensures that cache operations are atomic, preventing race conditions where different threads could interfere with each other, leading to faulty cache states. Ensuring thread-safe operations with mechanisms like mutexes or locks is crucial for maintaining data integrity and providing reliable performance .

The grading metrics for the proxy server project include a total of 20 points split evenly between code quality and performance. 10 points are awarded based on the correctness of the implementation concerning select-based socket programming, the thread pool, and a thread-safe cache, encouraging technically sound and error-free code. The other 10 points are based on the throughput of the proxy server, with maximum points given to the implementation achieving the highest performance, incentivizing efficient and high-performance code .

The 'pthreads' library facilitates the implementation of a multi-threaded proxy server by providing a standardized API for creating and managing threads. It allows for efficient concurrent processing of client requests, as each request can be handled by a separate thread, maximizing CPU utilization. Additionally, 'pthreads' offers synchronization primitives like mutexes and condition variables, essential for ensuring thread-safe operations on shared resources like the cache, thus meeting the requirement for robust and efficient multi-threaded operations in the proxy server .

Multi threaded proxy
In computer networks, a proxy server is a server  
that acts as an intermediary for requests from 
clients seeking resources
Step 1: Implement a barebones 
proxy
 Opens a TCP server socket to listen for TCP 
connections on a particular port. 
When a new connection is setup, the proxy
Rather than constantly poll sockets to receive 
data, you should implement 
network I/O code using the select call. Also, mak
Step 2: Make the proxy multi-
threaded
To improve the throughput offered, make your 
paid proxy multi-threaded. The proxy 
would work in the same way as above, excep
Step 3: Add a cache to the 
proxy
To further improve throughput, add a cache to your 
cheap proxy server. At any given time, 
the cache should contain at most

You might also like