You have a distributed system of nodes. There is only one node in the system that is running the class Executor. From this node you need to get the total RAM usage of each node in the cluster using the Classes defined below
import psutil
class Node:
def __init__(self, neighbors):
"""
Parameters
----------
neighbors: list(Node)
A list of nodes that this node is connected to
"""
self.neighbors = neighbors
def get_node_ram(self):
return psutil.virtual_memory().used
def send(msg):
"""A non-blocking method to pass a message. Triggers `on_receive`.
Parameters
----------
msg: str
A string message to be sent
"""
raise NotImplementedError
def on_receive(msg, sender):
"""Triggered when the ``send`` method is called
Parameters
----------
msg: str
The message from ``send``
sender: Node
The node from which send was called
"""
raise NotImplementedError
class Executor(Node):
def __init__(self):
pass
def on_recieve(msg, sender):
"""
Parameters
----------
msg: str
The message from ``send``
sender: Node
The node from which send was called
"""
raise NotImplementedErrorI got this question on a recent interview, I won't say the name because I signed an NDA, but I still wanted to discuss the problem. I had a really hard time wrapping my head around how send and on_recieve worked. I had a hard time with this because from my experience with RPC, which I think this question was modeled from, doesn't behave like this. Maybe there's something I can learn about distributed systems and how they communicate? I also want to know others thoughts on the "fairness" of this question, I needed a lot of prodding from the interviewer on how to solve this problem and I think it cost me the offer. I'll post my solution below in the comments.