def _load_average(self, rdesc):
        """ Time estimate using load averages. """
        credentials = get_credentials()

        min_cpus = rdesc.get('min_cpus', 0)
        if min_cpus:
            # Spread across LocalAllocators.
            rdesc['min_cpus'] = 1

        avail_cpus = 0
        with self._lock:
            best_host = None
            best_estimate = -2
            best_criteria = {'': 'No LocalAllocator results'}

            # Prefer not to repeat use of just-used allocator.
            prev_host = self._last_deployed
            prev_estimate = -2
            prev_criteria = None
            self._last_deployed = None

            # Drain _reply_q.
            while True:
                try:
                    self._reply_q.get_nowait()
                except Queue.Empty:
                    break

            # Get estimates via worker threads.
            todo = []
            max_workers = 10
            for i, host in enumerate(self.cluster):
                if i < max_workers:
                    worker_q = WorkerPool.get()
                    worker_q.put((self._get_estimate,
                                  (host, rdesc, credentials),
                                  {}, self._reply_q))
                else:
                    todo.append(host)

            # Process estimates.
            host_loads = []  # Sorted list of (load, criteria)
            for i in range(len(self.cluster)):
                worker_q, retval, exc, trace = self._reply_q.get()
                if exc:
                    self._logger.error(trace)
                    retval = None

                try:
                    next_host = todo.pop(0)
                except __HOLE__:
                    WorkerPool.release(worker_q)
                else:
                    worker_q.put((self._get_estimate,
                                  (next_host, rdesc, credentials),
                                  {}, self._reply_q))

                if retval is None:
                    continue
                host, estimate, criteria = retval
                if estimate is None or estimate < -1:
                    continue

                # Accumulate available cpus in cluster.
                avail_cpus += criteria['total_cpus']

                # CPU-adjusted load (if available).
                if 'loadavgs' in criteria:
                    load = criteria['loadavgs'][0] / criteria['total_cpus']
                else:  # Windows
                    load = 0.

                # Insertion sort of host_loads.
                if estimate >= 0 and min_cpus:
                    new_info = (load, criteria)
                    if host_loads:
                        for i, info in enumerate(host_loads):
                            if load < info[0]:
                                host_loads.insert(i, new_info)
                                break
                        else:
                            host_loads.append(new_info)
                    else:
                        host_loads.append(new_info)

                # Update best estimate.
                if host is prev_host:
                    prev_estimate = estimate
                    prev_criteria = criteria
                elif (best_estimate <= 0 and estimate > best_estimate) or \
                     (best_estimate >  0 and estimate < best_estimate):
                    best_host = host
                    best_estimate = estimate
                    best_criteria = criteria
                elif best_estimate == 0 and estimate == 0:
                    if 'loadavgs' in best_criteria:
                        best_load = best_criteria['loadavgs'][0]
                        if load < best_load:
                            best_host = host
                            best_estimate = estimate
                            best_criteria = criteria
                    else:
                        if 'loadavgs' in criteria:  # Prefer non-Windows.
                            best_host = host
                            best_estimate = estimate
                            best_criteria = criteria

            # If no alternative, repeat use of previous host.
            if best_estimate < 0 and prev_estimate >= 0:
                best_host = prev_host
                best_estimate = prev_estimate
                best_criteria = prev_criteria

            if avail_cpus < min_cpus:
                return (-2, {'min_cpus': 'want %d, available %d' \
                                         % (min_cpus, avail_cpus)})

            # Save best host in criteria in case we're asked to deploy.
            if best_host is not None:
                best_criteria['host'] = best_host
                if min_cpus:
                    # Save min_cpus hostnames in criteria.
                    hostnames = []
                    for load, criteria in host_loads:
                        hostname = criteria['hostnames'][0]
                        hostnames.append(hostname)
                        if len(hostnames) >= min_cpus:
                            break
                        total_cpus = criteria['total_cpus']
                        max_load = criteria.get('max_load', 1)
                        load *= total_cpus  # Restore from cpu-adjusted value.
                        max_load *= total_cpus
                        load += 1
                        while load < max_load and len(hostnames) < min_cpus:
                            hostnames.append(hostname)
                            load += 1
                        if len(hostnames) >= min_cpus:
                            break
                    if len(hostnames) < min_cpus:
                        return (-1, {'min_cpus': 'want %d, idle %d' \
                                                 % (min_cpus, len(hostnames))})
                    best_criteria['hostnames'] = hostnames

            return (best_estimate, best_criteria)
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/resource.py/ClusterAllocator._load_average