IPC Methods Performance Comparison

Infrastructure, Parallelism & Hardware Efficiency DS practice problem on Onlearn.

Difficulty: medium.

Topics: IPC Methods Performance Comparison, Shared Memory Latency, Unix Domain Sockets, Zero-Copy Buffer Transfer, Message Queue Throughput, Remote Procedure Call (RPC) Serialization, Distributed Systems, Operating Systems Architecture, High-Performance Computing, System Performance Profiling, Parallel Programming Models, Inter-Process Communication, Memory Management, Context Switching Overhead, Synchronization Primitives, Data Serialization Protocols.

In distributed ML training and inference pipelines, data must be transferred between processes using various Inter Process Communication (IPC) mechanisms such as pipes, shared memory, sockets, or message queues. Each method has different characteristics in terms of per message latency, data transfer bandwidth, and one time setup cost. Choosing the right IPC method can significantly impact pipeline throughput. Implement a function compare ipc methods that evaluates and ranks IPC methods based on their estimated performance for a given workload. The function receives: methods: a list of dictionaries, each with keys name (string), latency us (per message latency overhead in microseconds), bandwidth mbps (sustained transfer bandwidth in megabytes per second), and setup cost us (one time initialization cost in microseconds). message size bytes: the size of each message in bytes. num messages: the total number of messages to send. For each IPC method, compute: 1. The data transfer time per message in microseconds, derived from the message size and the method's bandwidth. 2. The total time per message (latency overhead plus transfer time). 3. The overall total time including the one time setup cost. 4. The throughput in messages per second. Return a list of result dictionaries sorted by total time in ascending order (fastest method first). Each result dictionary should have keys: name, total time us (rounded to 2 decimal places), and throughput msgs per sec (rounded to 2 decimal places).