| 215 | if clientId2gpuInfos[clientID]['usedNum'] == 0: |
| 216 | del clientId2gpuInfos[clientID] |
| 217 | logging.info(f"Client#{clientID} released all GPU resources") |
| 218 | |
| 219 | def main(): |
| 220 | config = load_runtime_config() |
| 221 | |
| 222 | dpcIp = config['DispatcherConfig']['dpcIp_'] |
| 223 | dpcPort = config['DispatcherConfig']['dpcPort_'] |
| 224 | listenIp = config['ClientConfig']['proxyIp_'] |
| 225 | listenPort = config['ClientConfig']['proxyPort_'] |
| 226 | |
| 227 | proxy = connect_to_dispatcher(dpcIp, dpcPort) |
| 228 | if proxy is None: |
| 229 | return |
| 230 | |
| 231 | logging.info(f"Connected to dispatcher({dpcIp}:{dpcPort})") |
| 232 | proxy_lock = threading.Lock() |
| 233 | |
| 234 | listen_proxy = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 235 | listen_proxy.bind((listenIp, listenPort)) |
| 236 | listen_proxy.listen() |
| 237 | logging.info(f"Listening on {listenIp}:{listenPort}") |
| 238 | |
| 239 | try: |
| 240 | while True: |
| 241 | conn, addr = listen_proxy.accept() |
| 242 | logging.debug(f"Accepted connection from {addr}") |
| 243 | threading.Thread(target=handle_client_worker, args=(conn, addr, proxy, proxy_lock)).start() |
| 244 | except KeyboardInterrupt: |
| 245 | logging.info("Shutting down...") |
| 246 | listen_proxy.close() |
| 247 | proxy.close() |
| 248 | |
| 249 | proxy.close() |
| 250 | |
| 251 | if __name__ == "__main__": |
| 252 | main() |