def server_instance_class(monkeysession, tmp_path_factory, worker_id): from secrets import choice from hangar.remote import server monkeysession.setattr(server, 'server_config', mock_server_config) monkeysession.setitem(hangar.constants.LMDB_SETTINGS, 'map_size', 2_000_000) monkeysession.setitem(hangar.backends.lmdb_30.LMDB_SETTINGS, 'map_size', 1_000_000) monkeysession.setitem(hangar.backends.lmdb_31.LMDB_SETTINGS, 'map_size', 1_000_000) monkeysession.setattr(hangar.backends.hdf5_00, 'COLLECTION_COUNT', 20) monkeysession.setattr(hangar.backends.hdf5_00, 'COLLECTION_SIZE', 20) monkeysession.setattr(hangar.backends.hdf5_01, 'COLLECTION_COUNT', 20) monkeysession.setattr(hangar.backends.hdf5_01, 'COLLECTION_SIZE', 20) monkeysession.setattr(hangar.backends.numpy_10, 'COLLECTION_SIZE', 100) possibble_addresses = [x for x in range(50000, 59999)] chosen_address = choice(possibble_addresses) address = f'localhost:{chosen_address}' base_tmpdir = tmp_path_factory.mktemp(f'{worker_id[-1]}') server, hangserver, _ = server.serve(str(base_tmpdir), overwrite=True, channel_address=address) server.start() yield address hangserver.close() server.stop(0.1) server.wait_for_termination(timeout=2)
def server_instance(monkeypatch, managed_tmpdir, worker_id): from secrets import choice from hangar.remote import server monkeypatch.setattr(server, 'server_config', mock_server_config) possibble_addresses = [x for x in range(50000, 59999)] chosen_address = choice(possibble_addresses) address = f'localhost:{chosen_address}' base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}') mkdir(base_tmpdir) server, hangserver, _ = server.serve(base_tmpdir, overwrite=True, channel_address=address) server.start() yield address hangserver.close() server.stop(0.1) server.wait_for_termination(timeout=2)
def server_instance(managed_tmpdir, worker_id): from hangar.remote.server import serve address = f'localhost:{randint(50000, 59999)}' base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}') mkdir(base_tmpdir) server, hangserver, _ = serve(base_tmpdir, overwrite=True, channel_address=address) server.start() yield address hangserver.env._close_environments() server.stop(0.1) time.sleep(0.2) if platform.system() == 'Windows': # time for open file handles to close before tmp dir can be removed. time.sleep(0.3)
def server_instance(managed_tmpdir, worker_id, monkeypatch): from secrets import choice from hangar.remote.server import serve possibble_addresses = [x for x in range(50000, 59999)] chosen_address = choice(possibble_addresses) address = f'localhost:{chosen_address}' base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}') mkdir(base_tmpdir) server, hangserver, _ = serve(base_tmpdir, overwrite=True, channel_address=address) monkeypatch.setitem(hangserver.CFG['SERVER_GRPC'], 'max_concurrent_rpcs', '20') monkeypatch.setitem(hangserver.CFG['SERVER_GRPC'], 'max_thread_pool_workers', '5') server.start() yield address hangserver.close() server.stop(0.1) server.wait_for_termination(timeout=10)
def server_instance_nbytes_limit(monkeypatch, managed_tmpdir, worker_id, mocker): from hangar.remote.server import serve address = f'localhost:{randint(50000, 59999)}' base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}') mkdir(base_tmpdir) server, hangserver, _ = serve(base_tmpdir, overwrite=True, channel_address=address) hangserver.CFG['SERVER_GRPC']['fetch_max_nbytes'] = '500000' hangserver.CFG['CLIENT_GRPC']['push_max_nbytes'] = '500000' server.start() yield address hangserver.env._close_environments() server.stop(0.05) time.sleep(0.1) if platform.system() == 'Windows': # time for open file handles to close before tmp dir can be removed. time.sleep(0.1)
def server(overwrite, ip, port, timeout): """Start a hangar server, initializing one if does not exist. The server is configured to top working in 24 Hours from the time it was initially started. To modify this value, please see the ``--timeout`` parameter. The hangar server directory layout, contents, and access conventions are similar, though significantly different enough to the regular user "client" implementation that it is not possible to fully access all information via regular API methods. These changes occur as a result of the uniformity of operations promised by both the RPC structure and negotiations between the client/server upon connection. More simply put, we know more, so we can optimize access more; similar, but not identical. """ from hangar.remote.server import serve P = os.getcwd() ip_port = f'{ip}:{port}' server, hangserver, channel_address = serve(P, overwrite, channel_address=ip_port) server.start() click.echo(f'Hangar Server Started') click.echo(f'* Start Time: {time.asctime()}') click.echo(f'* Base Directory Path: {P}') click.echo(f'* Operating on `IP_ADDRESS:PORT`: {channel_address}') try: startTime = time.time() while True: time.sleep(0.1) if time.time() - startTime > timeout: raise SystemExit except (KeyboardInterrupt, SystemExit): click.echo(f'Server Stopped at Time: {time.asctime()}') hangserver.close() server.stop(0)
def server_instance_push_restricted(monkeypatch, managed_tmpdir, worker_id): from hangar.remote import server from secrets import choice monkeypatch.setattr(server, 'server_config', mock_server_config) possibble_addresses = [x for x in range(50000, 59999)] chosen_address = choice(possibble_addresses) address = f'localhost:{chosen_address}' base_tmpdir = pjoin(managed_tmpdir, f'{worker_id[-1]}') mkdir(base_tmpdir) server, hangserver, _ = server.serve(base_tmpdir, overwrite=True, channel_address=address, restrict_push=True, username='******', password='******') server.start() yield address hangserver.env._close_environments() hangserver.close() server.stop(0.1) server.wait_for_termination(timeout=2)