Пример #1
0
def create_range():
    try:
        data = request.get_data()
        new_uuid = database.create_range(data)
        return json.dumps(new_uuid)
    except:
        return None, 500
Пример #2
0
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...')
    start_time = time.time()
    all_slots = db_api.get_slots(_range.uuid)
    for i in range(0, 5000, 2):