Commit 5cee2b77 authored by Ranadeep Biswas's avatar Ranadeep Biswas
Browse files

Store data from threads

parent 45091dfc
......@@ -5,6 +5,7 @@ use db::op;
use algo::txn;
use std::thread;
use std::sync::{Arc, Mutex};
pub fn do_bench(conn_str: String) {
let mut conn = mysql::Pool::new(conn_str.clone())
......@@ -13,44 +14,55 @@ pub fn do_bench(conn_str: String) {
.unwrap();
let n_vars = 1000;
let n_txn = 10;
let n_evts_per_txn = 10;
op::create_table(&mut conn);
op::create_vars(n_vars, &mut conn);
slowq::turn_on_slow_query(&mut conn);
slowq::clean_slow_query(&mut conn);
slowq::increase_max_connections(100000, &mut conn);
let mut threads = vec![];
for i in 0..5 {
let mut txns = vec![];
let mut conn_ids = vec![];
for _ in 0..n_txn {
txns.push(Arc::new(Mutex::new(txn::create_txn(
n_vars,
n_evts_per_txn,
))));
conn_ids.push(Arc::new(Mutex::new(0)));
}
for i in 0..n_txn {
let conn_str_ = conn_str.clone();
threads.push(
thread::Builder::new()
.name(format!("thread-{}", i))
.spawn(move || {
let n_txns = 10;
let n_evts = 10;
let mut txns = txn::create_txns(n_txns, n_vars, n_evts);
let mut loc_conn = mysql::Pool::new(conn_str_).unwrap().get_conn().unwrap();
println!(
"thread-{} using connection_id {}",
i,
op::get_connection_id(&mut loc_conn)
);
for ref mut txn in txns.iter_mut() {
op::do_transaction(txn, &mut loc_conn);
}
})
.unwrap(),
);
let mut curr_txn = txns[i].clone();
let mut curr_conn_id = conn_ids[i].clone();
threads.push(thread::spawn(move || {
let mut loc_conn = mysql::Pool::new(conn_str_).unwrap().get_conn().unwrap();
let mut curr_conn_id_ = curr_conn_id.lock().unwrap();
*curr_conn_id_ = op::get_connection_id(&mut loc_conn);
let mut curr_txn_ = curr_txn.lock().unwrap();
op::do_transaction(&mut curr_txn_, &mut loc_conn);
}));
}
for t in threads {
t.join().expect("thread failed");
}
for i in 0..n_txn {
println!(
"Connection id: {}\n{:?}\n",
*conn_ids[i].lock().unwrap(),
*txns[i].lock().unwrap()
)
}
// op::drop_database(&mut conn);
}
......@@ -30,6 +30,11 @@ pub fn clean_slow_query(conn: &mut mysql::PooledConn) {
conn.query("TRUNCATE TABLE mysql.slow_log").unwrap();
}
pub fn increase_max_connections(n_conn: u64, conn: &mut mysql::PooledConn) {
conn.query(format!("SET GLOBAL max_connections = {}", n_conn))
.unwrap();
}
fn get_slow_query(conn: &mut mysql::PooledConn) {
let slow_log: Vec<_> = conn.prep_exec("SELECT * FROM mysql.slow_log WHERE db=?", ("test",))
.map(|result| {
......
......@@ -46,11 +46,11 @@ fn main() {
let port = matches.value_of("mysql_port").unwrap_or("3306");
let user = matches.value_of("mysql_username").unwrap();
let sec = matches.value_of("mysql_secret").unwrap();
println!("{} {} {:?} {:?}", ip, port, user, sec);
// println!("{} {} {:?} {:?}", ip, port, user, sec);
let conn_str = format!("mysql://{}:{}@{}:{}", user, sec, ip, port);
println!("{}", conn_str);
// println!("{}", conn_str);
algo::bench::do_bench(conn_str);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment