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