0% found this document useful (0 votes)
5 views2 pages

Reflection

The report details the implementation of concurrency in a server using goroutines to handle multiple clients simultaneously while ensuring data consistency with a mutex. It addresses challenges such as client disconnects, race conditions, and invalid commands, providing solutions like error handling and command validation. Overall, these measures enhanced the reliability of the system under concurrent usage.

Uploaded by

sofonyastizazu29
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Reflection

The report details the implementation of concurrency in a server using goroutines to handle multiple clients simultaneously while ensuring data consistency with a mutex. It addresses challenges such as client disconnects, race conditions, and invalid commands, providing solutions like error handling and command validation. Overall, these measures enhanced the reliability of the system under concurrent usage.

Uploaded by

sofonyastizazu29
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Reflection Report

1. How Concurrency Was Implemented to Handle Multiple Clients


To allow the server to handle many clients at the same time, I used goroutines in Go.
• When a client connects, the server starts a new goroutine for that client. This means each
client gets its own lightweight "thread" to handle their commands without blocking
others.
• The server listens for connections using TCP ([Link]), which ensures reliable
communication between the client and the server.
This way, multiple clients can send requests to the server at the same time, and the server can
respond to them all without waiting for one client to finish.

2. Challenges Faced and How They Were Solved


1. Client Disconnects:
• Problem: If a client disconnected unexpectedly, it would sometimes cause the
server to crash or log errors.
• Solution: I added error handling in the client-handling code to detect and cleanly
close connections when errors occurred. I used defer [Link]() to
ensure the connection was always properly closed.
2. Multiple Clients Updating the Same Data:
• Problem: If two clients tried to modify or read the key-value store at the same
time, it could cause inconsistencies or crashes (a race condition).

• Solution: I used a [Link] to lock the key-value store when one client was
accessing it. This ensured only one client could make changes or read at a time,
avoiding conflicts.

3. Invalid Commands:
• Problem: If a client sent a wrong or incomplete command, the server didn’t know
how to handle it.
• Solution: I added checks to validate the commands. If the command was invalid,
the server responded with a clear error message like "ERROR: Unknown
command."
3. Ensuring Data Consistency During Concurrent Access
To keep the data consistent when multiple clients accessed it at the same time, I used a mutex
([Link]).

• Whenever a client wanted to read or change the data (like PUT, GET, or DELETE), the
server would lock the data using the mutex. This ensured that no other client could access
the data until the first client was done.
• Once the operation was complete, the server would unlock the mutex, allowing the next
client to proceed.
• This made sure that operations were completed one at a time, avoiding any conflicts or
errors.

Summary
I used goroutines to handle multiple clients at the same time and a mutex to make sure the data
stayed consistent even when many clients were connected. I also added error handling for
unexpected issues, like invalid commands or client disconnects. These steps made the system
reliable, even when multiple clients used it at once.

You might also like