MCPcopy
hub / github.com/uber/aresdb / FindDevice

Method FindDevice

query/device_manager.go:140–181  ·  view source on GitHub ↗

FindDevice finds a device to run a given query. If a device is not found, it will wait until the DeviceChoosingTimeout seconds elapse.

(query *queryCom.AQLQuery, requiredMem int, preferredDevice int, timeout int)

Source from the content-addressed store, hash-verified

138// FindDevice finds a device to run a given query. If a device is not found, it will wait until
139// the DeviceChoosingTimeout seconds elapse.
140func (d *DeviceManager) FindDevice(query *queryCom.AQLQuery, requiredMem int, preferredDevice int, timeout int) int {
141 if requiredMem > d.MaxAvailableMemory {
142 utils.GetQueryLogger().With(
143 "query", query,
144 "requiredMem", requiredMem,
145 "preferredDevice", preferredDevice,
146 "maxAvailableMem", d.MaxAvailableMemory,
147 ).Warn("exceeds max memory")
148 return -1
149 }
150
151 // no DeviceChoosingTimeout passed by request, using default DeviceChoosingTimeout.
152 if timeout <= 0 {
153 timeout = d.Timeout
154 }
155
156 timeoutDuration := time.Duration(timeout) * time.Second
157
158 start := utils.Now()
159 d.Lock()
160 device := -1
161 for {
162 if utils.Now().Sub(start) >= timeoutDuration {
163 utils.GetQueryLogger().With(
164 "query", query,
165 "requiredMem", requiredMem,
166 "preferredDevice", preferredDevice,
167 "timeout", timeout,
168 ).Error("DeviceChoosingTimeout when choosing the device for the query")
169 break
170 }
171
172 device = d.findDevice(query, requiredMem, preferredDevice)
173 if device >= 0 {
174 break
175 }
176 d.deviceAvailable.Wait()
177 }
178 d.Unlock()
179 utils.GetRootReporter().GetTimer(utils.QueryWaitForMemoryDuration).Record(utils.Now().Sub(start))
180 return device
181}
182
183// findDevice finds a device to run a given query according to certain strategy.If no such device can't
184// be found, return -1. Caller needs to hold the write lock.

Callers 2

FindDeviceForQueryMethod · 0.80

Calls 10

findDeviceMethod · 0.95
GetQueryLoggerFunction · 0.92
NowFunction · 0.92
GetRootReporterFunction · 0.92
GetTimerMethod · 0.80
WarnMethod · 0.65
WithMethod · 0.65
ErrorMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected