def __init__(self): Serialization().register_file_descriptor(DESCRIPTOR) self.__nodes = {} self.__default_node_address = '127.0.0.1:12000' self.provision_node('127.0.0.1', 12000) Remote().start("127.0.0.1", 12001)
async def main(): tracer = init_jaeger_tracer() opentracing.set_global_tracer(tracer) context = RootContext() Serialization().register_file_descriptor(DESCRIPTOR) Remote().start("127.0.0.1", 8000) clients = [] async def process_message(ctx: AbstractContext): msg = ctx.message if isinstance(msg, Connect): print(f'Client {msg.sender} connected') clients.append(msg.sender) await ctx.send(msg.sender, Connected(message='Welcome!')) elif isinstance(msg, SayRequest): for client in clients: await ctx.send(client, SayResponse(user_name=msg.user_name, message=msg.message)) elif isinstance(msg, NickRequest): for client in clients: await ctx.send(client, NickResponse(old_user_name=msg.old_user_name, new_user_name=msg.new_user_name)) props = OpenTracingFactory.get_props_with_open_tracing(Props.from_func(process_message), span_setup, span_setup) context.spawn_named(props, 'chatserver') input()
async def main(): context = RootContext() Serialization().register_file_descriptor(DESCRIPTOR) Remote().start("192.168.1.129", 12001) wg = asyncio.Event() message_count = 10000 props = Props.from_producer(lambda: LocalClient(0, message_count, wg, asyncio.get_event_loop())) pid = context.spawn(props) remote = PID(address="192.168.1.77:12000", id="remote") await context.request_future(remote, StartRemote(Sender=pid)) start = datetime.datetime.now() print('Starting to send') for i in range(message_count): await context.send(remote, Ping()) await wg.wait() elapsed = datetime.datetime.now() - start print(f'Elapsed {elapsed}') t = message_count * 2.0 / elapsed.total_seconds() print(f'Throughput {t} msg / sec') input()
def dispose(self): for process in self.__nodes.values(): process.kill() process.wait() Remote().shutdown(False)
def hello_grain_factory(self, factory: AbstractHelloGrain) -> None: self._hello_grain_factory = factory Remote().register_known_kind( 'HelloGrain', Props().from_producer(lambda: HelloGrainActor()))