MCPcopy Create free account
hub / github.com/ModelEngine-Group/flexai / handle_client_worker

Function handle_client_worker

GPU-Virtual-Service/gpu-remoting/proxy.py:102–215  ·  view source on GitHub ↗
(conn, addr, proxy, proxy_lock)

Source from the content-addressed store, hash-verified

100 gpuPropList.append(decompressed_gpuProp)
101
102 return gpuBasicInfoList, gpuPropList
103
104def handle_client_worker(conn, addr, proxy, proxy_lock):
105 logging.info(f"Accepted connection from {addr}")
106 clientID = None
107 try:
108 while True:
109 data = conn.recv(get_size_t_len())
110 if not data:
111 # logging.info("msg is None")
112 break
113
114 msg_len = struct.unpack('Q', data)[0]
115 if msg_len == 0:
116 logging.info("msg_len is 0")
117 break
118
119 msg = conn.recv(int(msg_len)).decode('utf-8')
120 if msg.startswith("GPUQuery:"):
121 data = msg.split(":", 1)[1].split(',')
122 clientID = int(data[0].strip())
123 gpuCount = int(data[1].strip().replace('\x00', ''))
124 logging.info(f"Client#{clientID}({addr}) requests {gpuCount} GPU(s)")
125
126 with clientId2gpuInfos_lock:
127 isClientIDExist = clientID in clientId2gpuInfos
128
129 gpuBasicInfoList, gpuPropList = None, None
130
131 if not isClientIDExist:
132 while True:
133 gpuBasicInfoList, gpuPropList = prepare_gpu_list(clientID, gpuCount, proxy, proxy_lock)
134 if gpuBasicInfoList is None or gpuPropList is None:
135 logging.error(f"Failed to get GPU resources for Client#{clientID}")
136 else:
137 break
138
139 with clientId2gpuInfos_lock:
140 clientId2gpuInfos[clientID] = {'usedNum': 1, 'gpuInfoList': gpuBasicInfoList, 'gpuPropList': gpuPropList, 'uniqueID': None, 'uniqueIDage': 0}
141 logging.debug(f"Client#{clientID} acquired GPU resources for the first time")
142 else:
143 with clientId2gpuInfos_lock:
144 gpuBasicInfoList, gpuPropList = clientId2gpuInfos[clientID]['gpuInfoList'], clientId2gpuInfos[clientID]['gpuPropList']
145 clientId2gpuInfos[clientID]['usedNum'] += 1
146 logging.debug(f"Client#{clientID} has already acquired GPU resources")
147
148 # with clientId2gpuInfos_lock:
149 # if clientID not in clientId2gpuInfos:
150 # gpuBasicInfoList, gpuPropList = prepare_gpu_list(clientID, gpuCount, proxy, proxy_lock)
151 # clientId2gpuInfos[clientID] = {'usedNum': 1, 'gpuInfoList': gpuBasicInfoList, 'gpuPropList': gpuPropList, 'uniqueID': None, 'uniqueIDage': 0}
152 # logging.debug(f"Client#{clientID} acquired GPU resources for the first time")
153 # else:
154 # gpuBasicInfoList, gpuPropList = clientId2gpuInfos[clientID]['gpuInfoList'], clientId2gpuInfos[clientID]['gpuPropList']
155 # clientId2gpuInfos[clientID]['usedNum'] += 1
156 # logging.debug(f"Client#{clientID} has already acquired GPU resources")
157
158 for dev in range(gpuCount):
159 gpuInfo, gpuProp = gpuBasicInfoList[dev], gpuPropList[dev]

Callers

nothing calls this directly

Calls 3

get_size_t_lenFunction · 0.70
prepare_gpu_listFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected