📝 Performance management in networking (10 MCQs)
📖 From Data Communication and Networks • 27. Network Management • 10 questions available
What is Performance management in networking?
Performance management focuses on measuring and optimizing network efficiency by monitoring metrics such as bandwidth usage, response time, and throughput to identify bottlenecks and ensure the network meets required service levels.
📝 All Performance management in networking MCQs
Q1. In the echo server code, when the call to returns 0, what is the most likely outcome for the current client connection?
📖 Explanation: When returns 0 it signals an orderly shutdown by the peer. The while condition becomes false, so the loop ends. Control then reaches the send statement, which transmits whatever data has been collected, and finally the socket is closed. No error is generated, and the server does not retry.
Q2. If the pointer is advanced by bytes after each successful recv, what would be the consequence of forgetting to also decrement by ?
📖 Explanation: If is advanced by bytes but is not reduced, the subsequent call to will still think the full original buffer size is available. Consequently, data may be written past the end of the allocated memory region, corrupting adjacent variables or causing a segmentation fault. Properly decrementing keeps the receive operation within safe bounds.
Q3. Suppose the server never resets the variable to zero before handling a new client connection. How would this affect performance over time?
📖 Explanation: Leaving unchanged means each new client inherits the total byte count from previous sessions. The subsequent `send(s, buffer, len, 0)` will therefore transmit an ever‑growing payload, many of which are stale data. This unnecessary traffic consumes bandwidth, increases latency, and ultimately lowers overall throughput as the server spends more time sending irrelevant bytes.
Q4. Compare using an infinite for loop `for(;;)` versus `while(1)` for the server's main loop in terms of readability and maintainability.
📖 Explanation: `for(;;)` and `while(1)` both create an infinite loop with identical compiled code, so performance is unchanged. However, `while(1)` explicitly states the intention to loop forever, making the logic clearer to readers unfamiliar with the C idiom. Clearer code reduces maintenance errors and speeds up onboarding of new developers.
Q5. Evaluate the impact of using non‑blocking sockets versus blocking sockets on server throughput.
📖 Explanation: Blocking sockets cause the thread to pause until data arrives, which can lead to idle CPU time when many connections are waiting, reducing aggregate throughput under load. Non‑blocking sockets allow the server to continue processing other tasks or connections while a particular socket has no data, improving concurrency and overall data‑transfer rates, though they add complexity.
Q6. Differentiate between handling each client sequentially in the same process versus spawning a new thread per client, focusing on CPU utilization and scalability.
📖 Explanation: A sequential design handles one client at a time, limiting concurrency but using minimal memory and avoiding context switches. Spawning a thread per client enables true parallel handling, improving responsiveness as multiple clients can be served simultaneously; however, each thread incurs scheduling and stack overhead, and excessive threads may degrade performance due to contention. The trade‑off hinges on expected client count and system resources.
Q7. Apply the principle of resource cleanup: why must the server call `close(s)` after sending the echo?
📖 Explanation: Calling `close(s)` releases the file descriptor associated with the client socket back to the operating system. If descriptors are not closed, the process eventually exhausts the limited descriptor table, leading to failure in accepting new connections. Proper cleanup also signals the kernel to reclaim associated buffers, preventing memory leaks and ensuring stable long‑term operation.
Q8. Explain the relationship between the variable `maxLen` and the allocated buffer size; how could an incorrect update to `maxLen` lead to a buffer overflow?
📖 Explanation: `maxLen` is intended to represent the remaining capacity of the receive buffer. After each successful `recv`, the code should subtract the number of bytes received (`n`) from `maxLen`. Failing to do so leaves `maxLen` larger than the actual free space, so a subsequent `recv` may write beyond the allocated buffer, corrupting memory and potentially causing crashes.
Q9. Synthesize an improvement to the given echo server that would allow it to handle multiple clients concurrently while preserving high performance. Which combination best achieves this goal?
📖 Explanation: Using a thread pool provides a balanced solution: a limited number of pre‑created worker threads receive accepted sockets and process the echo logic, avoiding the overhead of creating a thread for every connection while still allowing concurrent handling. This approach keeps latency low, maximizes CPU utilization, and simplifies resource management compared to creating a new thread per client or managing a fully event‑driven loop.
Q10. According to the code excerpt, which line number creates the listening socket with the `socket()` system call?
📖 Explanation: The excerpt states that lines 23 to 27 are responsible for creating the listen socket. In typical socket code, the `socket()` system call appears early in that block, usually on line 23, establishing the file descriptor that will later be bound and set to listen. Therefore, line 23 is the line that creates the listening socket.