You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to implement in zeroMQ something similar to this:
Where:
N user queues (PUSH --> PULL ) sends messages to the common queue (proxy frontent endpoint) in a Round Robin way (ZeroMQ push-pull pattern already handle this).
Proxy (PULL --> ROUTER) fowards messages from PULL socket (frontend) to ROUTER socket (backend)
N workers (REQ sockets) ask for tasks to the proxy ROUTER (backend) endpoint, whenever they free from their previus task (Load Balancing pattern).
Current solution
Currently i solve the proxy with the following (python) code
importzmqcontext=zmq.Context()
# Socket to receive messages from clientsfrontend=context.socket(zmq.PULL)
frontend.bind("tcp://*:5555")
# Socket to handle worker requests and send tasksbackend=context.socket(zmq.ROUTER)
backend.bind("tcp://*:5556")
# Poller to multiplex the sockets# (Listen from both sockets simultanesolly)poller=zmq.Poller()
poller.register(frontend, zmq.POLLIN)
poller.register(backend, zmq.POLLIN)
# Manually code to handle the load balancing pattern !!!available_tasks= []
available_workers= []
whileTrue:
socks=dict(poller.poll())
# New task arrivesifsocks.get(frontend) ==zmq.POLLIN:
task=frontend.recv_string()
available_tasks.append(task)
# New worker sends the "im free" notificationifsocks.get(backend) ==zmq.POLLIN:
message=backend.recv_multipart()
worker_id=message[0]
_=message[1] # The empty frameworker_request=message[2]
available_workers.append(worker_id)
ifavailable_tasksandavailable_workers:
# Send the next task to the requesting workertask=available_tasks.pop(0)
worker_id=available_workers.pop(0)
backend.send_multipart([worker_id, b'', task.encode()])
# Clean upfrontend.close()
backend.close()
context.term()
Idea:
Make Load Balancing code part of the ZeroMQ library to save code. Maybe the Proxy zeroMQ API could be a good interface for that:
importzmqcontext=zmq.Context()
# Set up the frontend (PULL socket)frontend=context.socket(zmq.PULL)
frontend.bind("tcp://*:5555")
# Set up the backend (ROUTER socket)backend=context.socket(zmq.ROUTER)
backend.bind("tcp://*:5556")
try:
zmq.proxy(frontend, backend)
exceptKeyboardInterrupt:
print("W: interrupt received, stopping…")
# Clean upfrontend.close()
backend.close()
context.term()
I'm new to the zeroMQ library and probably i am missing something, but after reading the guide (ch 3, the load-balancing pattern) i found that manual code is needed to handle this type of pattern.
The text was updated successfully, but these errors were encountered:
javiabellan
changed the title
proxy of PULL-->ROUTER ?
proxy of PULL-->ROUTER for solving the load-balancing pattern?
Jul 12, 2024
I want to implement in zeroMQ something similar to this:
Where:
Current solution
Currently i solve the proxy with the following (python) code
Idea:
Make Load Balancing code part of the ZeroMQ library to save code. Maybe the Proxy zeroMQ API could be a good interface for that:
I'm new to the zeroMQ library and probably i am missing something, but after reading the guide (ch 3, the load-balancing pattern) i found that manual code is needed to handle this type of pattern.
The text was updated successfully, but these errors were encountered: