Exemplo n.º 1
0
    def post(self, request, format=None):
        start = time.time()
        logger.info("Calling base64 encoding view")

        inputserializer = myappInputSerializer(data=request.data)
        inputserializer.is_valid(raise_exception=True)

        # processing
        message = request.data['message']
        encoding = encode(message)

        end = time.time()

        # saving transation
        comment = Comment('Everything is OK', 201, 'INFO')
        transaction = Transaction(userId=str(request.user), datetime=datetime.datetime.now(), comments=comment.__dict__, \
                                  duration=(end - start), serviceName='encoder64', serviceVersion='v1.0')
        insertdocument(transaction.__dict__, "Transaction")

        return Response({"encoding": encoding}, status=status.HTTP_200_OK)
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        inputserializer = myappInputVectorSerializer(data=request.data)
        if inputserializer.is_valid(raise_exception=True):
            start = time.time()
            logger.info("Calling Vector operation view")
            route = inputserializer.validated_data
            timeinput = route['time']
            speed = route['speed']

            difftime = []
            for x, y in zip(timeinput, timeinput[1:]):
                difftime.append(y - x)

            difftime.insert(0, 0)
            difftime.insert(1, timeinput[0])
            speed.insert(0, 0)
            distance = list(map(lambda x, y: x * y, difftime, speed))
            cumulated_distance = reduce(lambda x, y: x + y, distance, 0)

            end = time.time()
            results = dict()
            results['cumulated_distance'] = cumulated_distance
            # saving transation
            comment = Comment('Cumulated distance computation is OK', 201, 'INFO')
            transaction = Transaction(userId=str(request.user), datetime=datetime.datetime.now(),
                                      comments=comment.__dict__, duration=(end - start),
                                      serviceName='vectorOperation',
                                      serviceVersion='v1.0')
            insertdocument(transaction.__dict__, 'Transaction')
            return Response(results, status=status.HTTP_200_OK)
        else:
            data = {"Error": {"status": 400,
                              "message": "Output data was not valid - please correct the below errors",
                              "error_details": [{"field": key, "message": inputserializer.errors[key][0]} for key in
                                                inputserializer.errors.keys()]}}
            return Response(data, status=status.HTTP_400_BAD_REQUEST)
num_threads = 4

try:
    grades_table.index.create_index(1)
    grades_table.index.create_index(2)
    grades_table.index.create_index(3)
    grades_table.index.create_index(4)
except Exception as e:
    print('Index API not implemented properly, tests may fail.')

transaction_workers = []
insert_transactions = []
select_transactions = []
update_transactions = []
for i in range(num_threads):
    insert_transactions.append(Transaction())
    select_transactions.append(Transaction())
    update_transactions.append(Transaction())
    transaction_workers.append(TransactionWorker())
    transaction_workers[i].add_transaction(insert_transactions[i])
    #transaction_workers[i].add_transaction(select_transactions[i])
    #transaction_workers[i].add_transaction(update_transactions[i])
worker_keys = [ {} for t in transaction_workers ]

'''
for i in range(0, 10000):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [key, randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20)]
    q = Query(grades_table)
Exemplo n.º 4
0
    query.insert(906659671 + i, 93, 0, 0, 0)
    keys.append(906659671 + i)
insert_time_1 = process_time()

print("Inserting 10k records took:  \t\t\t", insert_time_1 - insert_time_0)

# Measuring update Performance
update_cols = [
    [randrange(0, 100), None, None, None, None],
    [None, randrange(0, 100), None, None, None],
    [None, None, randrange(0, 100), None, None],
    [None, None, None, randrange(0, 100), None],
    [None, None, None, None, randrange(0, 100)],
]

t = Transaction()
t.add_query(query.update, choice(keys), *choice(update_cols))
t.run()

exit()

update_time_0 = process_time()
for i in range(0, 10000):
    query.update(choice(keys), *(choice(update_cols)))
update_time_1 = process_time()
print("Updating 10k records took:  \t\t\t", update_time_1 - update_time_0)

# Measuring Select Performance
select_time_0 = process_time()
for i in range(0, 10000):
    query.select(choice(keys), [1, 1, 1, 1, 1])
Exemplo n.º 5
0
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(*records[key])

# Create transactions and assign them to workers
transactions = []
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker())

for i in range(10000):
    key = choice(keys)
    record = records[key]
    c = record[1]
    transaction = Transaction()
    for i in range(5):
        c += 1
        q = Query(grades_table)
        transaction.add_query(q.select, key, 0, [1, 1, 1, 1, 1]) 
        q = Query(grades_table)
        transaction.add_query(q.update, key, *[None, c, None, None, None])
    transaction_workers[i % num_threads].add_transaction(transaction)

threads = []
for transaction_worker in transaction_workers:
    threads.append(threading.Thread(target=transaction_worker.run, args = ()))

for thread in threads:
    thread.start()
Exemplo n.º 6
0
num_threads = 8

try:
    grades_table.index.create_index(1)
    grades_table.index.create_index(2)
    grades_table.index.create_index(3)
    grades_table.index.create_index(4)
except Exception as e:
    print('Index API not implemented properly, tests may fail.')

transaction_workers = []
insert_transactions = []
select_transactions = []
update_transactions = []
for i in range(num_threads):
    insert_transactions.append(Transaction(grades_table))
    select_transactions.append(Transaction(grades_table))
    update_transactions.append(Transaction(grades_table))
    transaction_workers.append(TransactionWorker())
    transaction_workers[i].add_transaction(insert_transactions[i])
    transaction_workers[i].add_transaction(select_transactions[i])
    transaction_workers[i].add_transaction(update_transactions[i])
worker_keys = [{} for t in transaction_workers]

for i in range(0, 1000):
    key = 92106429 + i
    keys.append(key)
    i = i % num_threads
    records[key] = [
        key,
        randint(i * 20, (i + 1) * 20),
Exemplo n.º 7
0
    key = 92106429 + i
    keys.append(key)
    records[key] = [key, 0, 0, 0, 0]
    q = Query(grades_table)
    q.insert(*records[key])

# create TransactionWorkers
transaction_workers = []
for i in range(num_threads):
    transaction_workers.append(TransactionWorker([]))

# generates 10k random transactions
# each transaction will increment the first column of a record 5 times
for i in range(10000):
    k = randint(0, 2000 - 1)
    transaction = Transaction(q)
    for j in range(5):
        key = keys[k * 5 + j]
        q = Query(grades_table)
        transaction.add_query(q.select, key, 0, [1, 1, 1, 1, 1])
        q = Query(grades_table)
        transaction.add_query(q.increment, key, 1)
    transaction_workers[i % num_threads].add_transaction(transaction)

threads = []
for transaction_worker in transaction_workers:
    threads.append(threading.Thread(target=transaction_worker.run, args=()))

for i, thread in enumerate(threads):
    print('Thread', i, 'started')
    thread.start()
try:
    grades_table.index.create_index(1)
    grades_table.index.create_index(2)
    grades_table.index.create_index(3)
    grades_table.index.create_index(4)
except Exception as e:
    print('Index API not implemented properly, tests may fail.')

keys = []
records = {}
seed(3562901)

insert_transactions = []
transaction_workers = []
for i in range(num_threads):
    insert_transactions.append(Transaction())
    transaction_workers.append(TransactionWorker())
    transaction_workers[i].add_transaction(insert_transactions[i])

for i in range(0, 1000):
    key = 92106429 + i
    keys.append(key)
    records[key] = [
        key,
        randint(0, 20),
        randint(0, 20),
        randint(0, 20),
        randint(0, 20)
    ]
    q = Query(grades_table)
    t = insert_transactions[i % num_threads]
Exemplo n.º 9
0
    query.insert(906659671 + i, 93, 0, 0, 0)
    keys.append(906659671 + i)
insert_time_1 = process_time()

print("Inserting 10k records took:  \t\t\t", insert_time_1 - insert_time_0)

# Measuring update Performance
update_cols = [
    [randrange(0, 100), None, None, None, None],
    [None, randrange(0, 100), None, None, None],
    [None, None, randrange(0, 100), None, None],
    [None, None, None, randrange(0, 100), None],
    [None, None, None, None, randrange(0, 100)],
]

t = Transaction()
key = choice(keys)
t.add_query(query.update, key, *choice(update_cols))
t.add_query(query.select, key, 0, [1, 1, 1, 1, 1])
t.run()

exit()

update_time_0 = process_time()
for i in range(0, 10000):
    query.update(choice(keys), *(choice(update_cols)))
update_time_1 = process_time()
print("Updating 10k records took:  \t\t\t", update_time_1 - update_time_0)

# Measuring Select Performance
select_time_0 = process_time()
Exemplo n.º 10
0
# l = Logger("log")
# l.write(1,"w",0,5)
# l.write(2,"u",5,50)
# l.write(2,"u",3,90)
# l.write(3,"u",9,50)
# print("reading all the lines from newest to oldest")
# l.read()
# print("reading all the lines of thread id 2")
# print(l.read_tid(2))
db = Database()

grades_table = db.create_table('Grades', 5, 0)
#populate the table

q = Query(grades_table)
# print(inspect.getfullargspec(q.update))
t1 = Transaction()
t2 = Transaction()
t3 = Transaction()
t3.add_query(q.update, 1, *[6, 7, 8, 9, 10])
t1.add_query(q.insert, *[1, 2, 3, 4, 5])
t1.add_query(q.insert, *[0, 1, 2, 2, 5])
t2.add_query(q.insert, *[6, 7, 8, 9, 10])
t3.add_query(q.insert, *[6, 7, 8, 9, 10])
t3.add_query(q.insert, *[6, 7, 8, 9, 10])
txn_worker = TransactionWorker([t1, t2, t3])
th1 = threading.Thread(target=txn_worker.run)
th1.start()

# l = Logger("log")