예제 #1
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])
select_time_1 = process_time()
예제 #2
0
# 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()

for thread in threads:
    thread.join()

num_committed_transactions = sum(t.result for t in transaction_workers)
예제 #3
0
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()
for i in range(0, 10000):
    query.select(choice(keys), [1, 1, 1, 1, 1])
예제 #4
0
    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()

for i, thread in enumerate(threads):
    thread.join()
    print('Thread', i, 'finished')
예제 #5
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")