Beispiel #1
0
def find_range(range_uuid=None):
    try:
        # if uuid is none, get all ranges.
        ranges = database.get_ranges(range_uuid)
        return json.dumps(ranges)
    except:
        return None, 500
Beispiel #2
0
#!/usr/bin/env python3

from db_api import Database
from slot_range import SlotRange
from slot import Slot

from uuid import uuid4
import time

if __name__ == "__main__":
    db_api = Database()
    start_time = time.time()
    print('Timer started.\nGetting ranges...')
    all_ranges = db_api.get_ranges()
    print('Got {} ranges in {} seconds.'.format(len(all_ranges),
                                                time.time() - start_time))
    if len(all_ranges) == 0:
        uuid = uuid4()
        db_api.create_range(0, 10000)
        all_ranges = db_api.get_ranges()
    the_range = all_ranges[0]
    _range = SlotRange(the_range['start'],
                       the_range['end'],
                       the_range['uuid'])
    print('Allocating via nightmare scenario...')
    start_time = time.time()
    for i in range(0, 5000):
        db_api.create_slot(_range.uuid)
    print('Initial allocation of 5000 slots done in {} seconds...'.format(
        time.time() - start_time))
    print('Deallocating every *other* slot...')