Beispiel #1
0
def rse_update(once=False,
               process=0,
               total_processes=1,
               thread=0,
               threads_per_process=1):
    """
    Main loop to check and update the RSE Counters.
    """

    logging.info('rse_update: starting')

    logging.info('rse_update: started')

    while not graceful_stop.is_set():
        try:
            # Select a bunch of rses for to update for this worker
            start = time.time()  # NOQA
            rse_ids = get_updated_rse_counters(
                total_workers=total_processes * threads_per_process - 1,
                worker_number=process * threads_per_process + thread)
            logging.debug('Index query time %f size=%d' %
                          (time.time() - start, len(rse_ids)))

            # If the list is empty, sent the worker to sleep
            if not rse_ids and not once:
                logging.info('rse_update[%s/%s] did not get any work' %
                             (process * threads_per_process + thread,
                              total_processes * threads_per_process - 1))
                time.sleep(10)
            else:
                for rse_id in rse_ids:
                    if graceful_stop.is_set():
                        break
                    start_time = time.time()
                    update_rse_counter(rse_id=rse_id)
                    logging.debug(
                        'rse_update[%s/%s]: update of rse "%s" took %f' %
                        (process * threads_per_process + thread,
                         total_processes * threads_per_process - 1, rse_id,
                         time.time() - start_time))
        except Exception:
            logging.error(traceback.format_exc())
        if once:
            break

    logging.info('rse_update: graceful stop requested')

    logging.info('rse_update: graceful stop done')
Beispiel #2
0
def rse_update(once=False):
    """
    Main loop to check and update the RSE Counters.
    """

    logging.info('rse_update: starting')

    logging.info('rse_update: started')

    # Make an initial heartbeat so that all abacus-rse daemons have the correct worker number on the next try
    executable = 'abacus-rse'
    hostname = socket.gethostname()
    pid = os.getpid()
    current_thread = threading.current_thread()
    live(executable=executable, hostname=hostname, pid=pid, thread=current_thread)

    while not graceful_stop.is_set():
        try:
            # Heartbeat
            heartbeat = live(executable=executable, hostname=hostname, pid=pid, thread=current_thread)

            # Select a bunch of rses for to update for this worker
            start = time.time()  # NOQA
            rse_ids = get_updated_rse_counters(total_workers=heartbeat['nr_threads'],
                                               worker_number=heartbeat['assign_thread'])
            logging.debug('Index query time %f size=%d' % (time.time() - start, len(rse_ids)))

            # If the list is empty, sent the worker to sleep
            if not rse_ids and not once:
                logging.info('rse_update[%s/%s] did not get any work' % (heartbeat['assign_thread'], heartbeat['nr_threads'] - 1))
                time.sleep(10)
            else:
                for rse_id in rse_ids:
                    if graceful_stop.is_set():
                        break
                    start_time = time.time()
                    update_rse_counter(rse_id=rse_id)
                    logging.debug('rse_update[%s/%s]: update of rse "%s" took %f' % (heartbeat['assign_thread'], heartbeat['nr_threads'] - 1, rse_id, time.time() - start_time))
        except Exception:
            logging.error(traceback.format_exc())
        if once:
            break

    logging.info('rse_update: graceful stop requested')
    die(executable=executable, hostname=hostname, pid=pid, thread=current_thread)
    logging.info('rse_update: graceful stop done')
Beispiel #3
0
def run_once(heartbeat_handler, **_kwargs):
    worker_number, total_workers, logger = heartbeat_handler.live()

    # Select a bunch of rses for to update for this worker
    start = time.time()  # NOQA
    rse_ids = get_updated_rse_counters(total_workers=total_workers,
                                       worker_number=worker_number)
    logger(logging.DEBUG, 'Index query time %f size=%d' % (time.time() - start, len(rse_ids)))

    # If the list is empty, sent the worker to sleep
    if not rse_ids:
        logger(logging.INFO, 'did not get any work')
        return

    for rse_id in rse_ids:
        worker_number, total_workers, logger = heartbeat_handler.live()
        if graceful_stop.is_set():
            break
        start_time = time.time()
        update_rse_counter(rse_id=rse_id)
        logger(logging.DEBUG, 'update of rse "%s" took %f' % (rse_id, time.time() - start_time))