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–216  ·  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 priority = int(data[2].strip().replace('\x00', ''))
125 logging.info(f"Client#{clientID}({addr}) requests {gpuCount} GPU(s)")
126
127 with clientId2gpuInfos_lock:
128 isClientIDExist = clientID in clientId2gpuInfos
129
130 gpuBasicInfoList, gpuPropList = None, None
131
132 if not isClientIDExist:
133 while True:
134 gpuBasicInfoList, gpuPropList = prepare_gpu_list(clientID, gpuCount, priority, proxy, proxy_lock)
135 if gpuBasicInfoList is None or gpuPropList is None:
136 logging.error(f"Failed to get GPU resources for Client#{clientID}")
137 else:
138 break
139
140 with clientId2gpuInfos_lock:
141 clientId2gpuInfos[clientID] = {'usedNum': 1, 'gpuInfoList': gpuBasicInfoList, 'gpuPropList': gpuPropList, 'uniqueID': None, 'uniqueIDage': 0}
142 logging.debug(f"Client#{clientID} acquired GPU resources for the first time")
143 else:
144 with clientId2gpuInfos_lock:
145 gpuBasicInfoList, gpuPropList = clientId2gpuInfos[clientID]['gpuInfoList'], clientId2gpuInfos[clientID]['gpuPropList']
146 clientId2gpuInfos[clientID]['usedNum'] += 1
147 logging.debug(f"Client#{clientID} has already acquired GPU resources")
148
149 # with clientId2gpuInfos_lock:
150 # if clientID not in clientId2gpuInfos:
151 # gpuBasicInfoList, gpuPropList = prepare_gpu_list(clientID, gpuCount, proxy, proxy_lock)
152 # clientId2gpuInfos[clientID] = {'usedNum': 1, 'gpuInfoList': gpuBasicInfoList, 'gpuPropList': gpuPropList, 'uniqueID': None, 'uniqueIDage': 0}
153 # logging.debug(f"Client#{clientID} acquired GPU resources for the first time")
154 # else:
155 # gpuBasicInfoList, gpuPropList = clientId2gpuInfos[clientID]['gpuInfoList'], clientId2gpuInfos[clientID]['gpuPropList']
156 # clientId2gpuInfos[clientID]['usedNum'] += 1
157 # logging.debug(f"Client#{clientID} has already acquired GPU resources")
158
159 for dev in range(gpuCount):

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