Esempio n. 1
0
def create_threads_and_run(dbname, NUM_THREADS):
    
    conn = None
    try:
        #conn = utils.connect_to_db(dbname, 'postgres', 'localhost', 'akul')
        client,conn = mongoConnect.connect_to_DB(dbname)
        
        if(conn == None):
                print "Connection to database failed. Please try again!"

        else:
                print "Connected to DB successfully!"
                
                threads = []	
                #Create and start all threads
                for i in range(0, NUM_THREADS):
                        process = threading.Thread(target=run_all_exp, args=(conn, i+1))
                        process.start()
                        threads.append(process)

                #Compile results together
                for process in threads:
                        process.join()

                #conn.commit()

    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            print ""
def record_delete_times(): 
    
    update_times  = dict()
    client_xs,database_xs = mongoConnect.connect_to_DB(mongoConnect.xs_db)
    client_s,database_s = mongoConnect.connect_to_DB(mongoConnect.s_db)
    client_m,database_m = mongoConnect.connect_to_DB(mongoConnect.m_db)
    client_l,database_l = mongoConnect.connect_to_DB(mongoConnect.l_db)

    xs_time = delete(database_xs)
    s_time = delete(database_s)
    m_time = delete(database_m)
    l_time = delete(database_l)
    
    update_times['XS'] = xs_time
    update_times['S'] = s_time
    update_times['M'] = m_time
    update_times['L'] = l_time
    
    return update_times
def record_advanced_join_times():
    
    join_times  = dict()
    client_xs,database_xs = mongoConnect.connect_to_DB(mongoConnect.xs_db)
    client_s,database_s = mongoConnect.connect_to_DB(mongoConnect.s_db)
    client_m,database_m = mongoConnect.connect_to_DB(mongoConnect.m_db)
    client_l,database_l = mongoConnect.connect_to_DB(mongoConnect.l_db)

    xs_time = advanced_join(database_xs)
    s_time = advanced_join(database_s)
    m_time = advanced_join(database_m)
    l_time = advanced_join(database_l)
    
    join_times['XS'] = xs_time
    join_times['S'] = s_time
    join_times['M'] = m_time
    join_times['L'] = l_time

    return join_times
def record_conditional_select_times(): 
    
    select_times  = dict()
    client_xs,database_xs = mongoConnect.connect_to_DB(mongoConnect.xs_db)
    client_s,database_s = mongoConnect.connect_to_DB(mongoConnect.s_db)
    client_m,database_m = mongoConnect.connect_to_DB(mongoConnect.m_db)
    client_l,database_l = mongoConnect.connect_to_DB(mongoConnect.l_db)

    xs_time = conditional_selects(database_xs)
    s_time = conditional_selects(database_s)
    m_time = conditional_selects(database_m)
    l_time = conditional_selects(database_l)
    
    select_times['XS'] = xs_time
    select_times['S'] = s_time
    select_times['M'] = m_time
    select_times['L'] = l_time
    
    return select_times
def record_aggregate_times():
    
    aggregate_times  = dict()
    client_l,database_l = mongoConnect.connect_to_DB(mongoConnect.l_db)

    sum_time,avg_time,min_time,max_time,count_time = aggregate_queries(database_l)
    #avg_time = advanced_join(database_s)
    #min_time = advanced_join(database_m)
    #max_time = advanced_join(database_l)
    
    aggregate_times['avg'] = avg_time
    aggregate_times['max'] = max_time
    aggregate_times['min'] = min_time
    aggregate_times['sum'] = sum_time
    aggregate_times['count'] = count_time

    return aggregate_times