Skip to content
Permalink
Browse files

feat(router): add a block router for benchmarking

  • Loading branch information...
hanxiao committed Sep 23, 2019
1 parent ea69135 commit 8fbb094526eddc0ed1233061b2ca018832ecd060
Showing with 15 additions and 1 deletion.
  1. +0 −1 gnes/cli/parser.py
  2. +15 −0 gnes/router/map.py
@@ -140,7 +140,6 @@ def set_composer_flask_parser(parser=None):
def set_service_parser(parser=None):
from ..service.base import SocketType, BaseService, ParallelType
import random
import uuid
if not parser:
parser = set_base_parser()
min_port, max_port = 49152, 65536
@@ -20,7 +20,22 @@
from ..proto import gnes_pb2


class BlockRouter(BaseMapRouter):
"""Wait for 'sleep_sec' seconds and forward messages, useful for benchmark"""

def __init__(self, sleep_sec: int = 5, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sleep_sec = sleep_sec

def apply(self, msg: 'gnes_pb2.Message', *args, **kwargs):
import time
time.sleep(self.sleep_sec)


class PublishRouter(BaseMapRouter):
"""Copy a message 'num_part' time and forward it, useful for PUB-SUB sockets.
'num_part' is an indicator for downstream sync-barrier, e.g. a ReduceRouter
"""

def __init__(self, num_part: int, *args, **kwargs):
super().__init__(*args, **kwargs)

0 comments on commit 8fbb094

Please sign in to comment.
You can’t perform that action at this time.