Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
model 3 half reasonable
Browse files Browse the repository at this point in the history
  • Loading branch information
taivop committed Dec 18, 2016
1 parent 38d07e0 commit 090d9ff
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 9 deletions.
1 change: 1 addition & 0 deletions scripts/oct/mva3_main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addpath ("./scripts/oct/")%nS = 5 % number of servers%nT = 32 % number of threads%nC = 180 % number of clients%pW = 5 / 100 % proportion of writes%%tNW_g = 2.826752%tLB_g = 0.003863378%tMC_g = 3.048588%tNW_s = 2.858229%tLB_s = 0.003403551%tMC_s = 3.122988arg_list = argv ();num_args_required = 11;if(length(arg_list) != num_args_required) printf("Check usage: %d arguments given, %d required.\n", length(arg_list), num_args_required); return;endifoffset = 1;result_path = arg_list{1}nS = str2num(arg_list{1 + offset}) % number of serversnT = str2num(arg_list{2 + offset}) % number of threadsnC = str2num(arg_list{3 + offset}) % number of clientspW = str2num(arg_list{4 + offset}) / 100 % proportion of writestNW_g = str2num(arg_list{5 + offset})tNW_s = str2num(arg_list{6 + offset})tLB_g = str2num(arg_list{7 + offset})tLB_s = str2num(arg_list{8 + offset})tWW = str2num(arg_list{9 + offset})tRW = str2num(arg_list{10 + offset})[U, R, Q, X] = mva_model1_multiclass(result_path, nS, nT, nC, pW, tNW_g, tNW_s, tLB_g, tLB_s, tWW, tRW);
Expand Down
1 change: 1 addition & 0 deletions scripts/oct/mva_model3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function [U, R, Q, X] = mva_model2(result_path, nS, nT, nC, pW, tNW_g, tNW_s, tLB_g, tLB_s, tWW, tRW);pkg load queueing;% ---- Setup ----nK = 1 + 1 + nS + nS + 1; % network + LoadBalancer + ReadWorkers + WriteWorker + networkC_GET = 1;C_SET = 2;ind_RW = 3:3+nS-1; % ReadWorkerind_WW = 3+nS:3+2*nS-1; % WriteWorker% ---- Inputs to the model ----% N -- Population size (number of requests in the system, N ≥ 0). If N == 0, this function returns U = R = Q = X = 0N = zeros(2, 1);N(2) = round(nC * pW);N(1) = nC - N(2);% S -- S(k) is the mean service time at center k (S(k) ≥ 0).S = zeros(2, nK);S(C_GET, 1) = tNW_g / 1000; % ms -> sS(C_GET, 2) = tLB_g / 1000; % ms -> sS(C_GET, ind_RW) = tRW / 1000; % ms -> sS(C_GET, nK) = S(C_GET, 1);S(C_SET, 1) = tNW_s / 1000; % ms -> sS(C_SET, 2) = tLB_s / 1000; % ms -> sS(C_SET, ind_WW) = tWW / 1000; % ms -> sS(C_SET, nK) = S(C_SET, 1);S(C_GET, ind_WW) = S(C_SET, ind_WW); % these should not matterS(C_SET, ind_RW) = S(C_GET, ind_RW); % these should not matter% V -- V(k) is the average number of visits to service center k (V(k) ≥ 0).V = zeros(2, nK);V(C_GET, 1:2) = 1;V(C_GET, ind_RW) = 1 / nS;V(C_GET, nK) = 1;V(C_SET, 1:2) = 1;V(C_SET, ind_WW) = 1 / nS;V(C_SET, nK) = 1;% m -- m(k) is the number of servers at center k (if m is a scalar, all centers have that number of servers).% If m(k) < 1, center k is a delay center (IS); otherwise it is a regular queueing center (FCFS, LCFS-PR or PS) with m(k) servers.% Default is m(k) = 1 for all k (each service center has a single server).m = ones(nK, 1);m(1) = 0; # delay centerm(2) = 1; # M/M/1m(ind_RW) = nT; # M/M/mm(ind_WW) = 1; # M/M/1m(nK) = 0; # delay center% Z -- External delay for customers (Z ≥ 0). Default is 0.Z = zeros(2, 1);% ---- Results ----[U, R, Q, X] = qncmmva (N, S, V, m, Z);save(result_path, "-v7", "N", "S", "V", "m", "Z", "U", "R", "Q", "X");% U -- If k is a FCFS, LCFS-PR or PS node (m(k) ≥ 1), then U(k) is the utilization of center k, 0 ≤ U(k) ≤ 1. If k is an IS node (m(k) < 1), then U(k) is the traffic intensity defined as X(k)*S(k). In this case the value of U(k) may be greater than one.% R -- R(k) is the response time at center k. The Residence Time at center k is R(k) * V(k). The system response time Rsys can be computed either as Rsys = N/Xsys - Z or as Rsys = dot(R,V)% Q -- Q(k) is the average number of requests at center k. The number of requests in the system can be computed either as sum(Q), or using the formula N-Xsys*Z.% X -- X(k) is the throughput of center k. The system throughput Xsys can be computed as Xsys = X(1) / V(1)endfunction
Expand Down
17 changes: 8 additions & 9 deletions scripts/r/part3_network_model2.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ model_inputs <- function(requests, mss) {
requests_get <- requests %>% filter(type == "GET")
requests_set <- requests %>% filter(type == "SET")

T_seconds <- (max(requests$timeDequeued)-min(requests$timeDequeued)) / 1000 # total time
tps_WW <- nrow(requests_set) / SAMPLING_RATE / T_seconds / num_servers

res <- list()
res$tLB_get <- mean(requests_get$timeEnqueued-requests_get$timeCreated)
res$tLB_set <- mean(requests_set$timeEnqueued-requests_set$timeCreated)
res$tRW <- mean(requests_get$timeReturned-requests_get$timeDequeued)
res$tWW <- mean(requests_set$timeForwarded-requests_set$timeDequeued)
res$tMC <- mean(requests_set$timeReceived-requests_set$timeForwarded)
res$tWWR <- mean(requests_set$timeReturned-requests_set$timeReceived)
res$tWW <- 1/tps_WW * 1000

rt_middleware_get <- mean(requests_get$timeReturned-requests_get$timeCreated)
rt_middleware_set <- mean(requests_set$timeReturned-requests_set$timeCreated)
Expand Down Expand Up @@ -68,6 +69,7 @@ num_threads = 32
num_clients = 180
perc_writes = 5
prop_writes = perc_writes / 100
SAMPLING_RATE <- 1/10

mss <- memaslap_summary(memaslap) %>%
mutate(type="actual")
Expand All @@ -79,20 +81,17 @@ octave_output_dir <- paste0(octave_dir_base, "/model2/", dir_name_end)
system(paste0("mkdir -p ", octave_output_dir))
octave_output_file <- paste0(octave_output_dir, "/results.mat")
arg_list <- paste(octave_output_file,
num_servers, num_replication, num_threads, num_clients,
perc_writes,
num_servers, num_threads, num_clients, perc_writes,
inputs$tNW_get, inputs$tNW_set,
inputs$tLB_get, inputs$tLB_set,
inputs$tWW, inputs$tRW, inputs$tMC, inputs$tWWR,
inputs$tWW, inputs$tRW,
collapse=" ")
system(paste0("octave scripts/oct/mva2_main.m ", arg_list))
system(paste0("octave scripts/oct/mva3_main.m ", arg_list))
mva <- readMat(octave_output_file)

K <- ncol(mva$U) # number of nodes in the network
ind_RW = 3:(3+num_servers-1) # ReadWorker devices
ind_WW = (3+num_servers):(3+2*num_servers-1) # WriteWorker devices
ind_MC = (3+2*num_servers):(3+3*num_servers-1)
ind_WWR = (3+3*num_servers):(K-1) # WriteWorkerRet

predicted <- list()
predicted$type <- "predicted"
Expand Down
135 changes: 135 additions & 0 deletions scripts/r/part3_network_model3.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
source("scripts/r/common.r")
source("scripts/r/ms3_common.r")

# ---- Directories and files ----
output_dir <- "results/analysis/part3_network"
octave_dir_base <- paste0(output_dir, "/mva")
data_source_dir <- "results/replication"

# ---- Helper function ----
normalise_request_log_df <- function(df) {

first_request_time <- min(df$timeCreated)
last_request_time <- max(df$timeCreated)
DROP_TIMES_BEFORE = first_request_time + 2 * 60 * 1000
DROP_TIMES_AFTER = last_request_time - 2 * 60 * 1000

df2 <- df %>% filter(timeCreated > DROP_TIMES_BEFORE &
timeCreated <= DROP_TIMES_AFTER)
return(df2)
}

model_inputs <- function(requests, mss) {

requests_get <- requests %>% filter(type == "GET")
requests_set <- requests %>% filter(type == "SET")

T_seconds <- (max(requests$timeDequeued)-min(requests$timeDequeued)) / 1000 # total time
tps_WW <- nrow(requests_set) / SAMPLING_RATE / T_seconds / num_servers

res <- list()
res$tLB_get <- mean(requests_get$timeEnqueued-requests_get$timeCreated)
res$tLB_set <- mean(requests_set$timeEnqueued-requests_set$timeCreated)
res$tRW <- mean(requests_get$timeReturned-requests_get$timeDequeued)
res$tWW <- 1/tps_WW * 1000
res$tMC <- mean(requests_set$timeReturned-requests_set$timeForwarded)

rt_middleware_get <- mean(requests_get$timeReturned-requests_get$timeCreated)
rt_middleware_set <- mean(requests_set$timeReturned-requests_set$timeCreated)
rt_memaslap_get <- mss$mean_response_time_get
rt_memaslap_set <- mss$mean_response_time_set

res$tNW_get <- (rt_memaslap_get-rt_middleware_get)/2
res$tNW_set <- (rt_memaslap_set-rt_middleware_set)/2

return(res)
}

exp_dir <- "./results/replication/S5_R1_rep5"

memaslap_file <- paste0(exp_dir, "/memaslap_stats.csv")
requests_file <- paste0(exp_dir, "/request.log")

# ---- Reading data ----
memaslap <- file_to_df(memaslap_file) %>% mutate(repetition=0)
requests <- file_to_df(requests_file, sep=",") %>%
normalise_request_log_df()
requests_get <- requests %>% filter(type=="GET")
requests_set <- requests %>% filter(type=="SET")

# ---- Preprocessing ----
dir_name_regex <- paste0("/S(\\d)_R(\\d)_rep(\\d)$")
result_params <- as.data.frame(str_match(exp_dir, dir_name_regex))

dir_name_end <- substr(result_params$V1, 2,
nchar(as.character(result_params$V1)))
num_servers = as.numeric(as.character(result_params$V2))
num_replication = as.numeric(as.character(result_params$V3))
num_repetition = result_params$V4
num_threads = 32
num_clients = 180
perc_writes = 5
prop_writes = perc_writes / 100
SAMPLING_RATE <- 1/10

mss <- memaslap_summary(memaslap) %>%
mutate(type="actual")

inputs <- model_inputs(requests, mss) %>% as.data.frame()

# ---- Model results ----
octave_output_dir <- paste0(octave_dir_base, "/model2/", dir_name_end)
system(paste0("mkdir -p ", octave_output_dir))
octave_output_file <- paste0(octave_output_dir, "/results.mat")
arg_list <- paste(octave_output_file,
num_servers, num_replication, num_threads, num_clients, perc_writes,
inputs$tNW_get, inputs$tNW_set,
inputs$tLB_get, inputs$tLB_set,
inputs$tWW, inputs$tRW, inputs$tMC, 0,
collapse=" ")
system(paste0("octave scripts/oct/mva2_main.m ", arg_list))
mva <- readMat(octave_output_file)

K <- ncol(mva$U) # number of nodes in the network
ind_RW = 3:(3+num_servers-1) # ReadWorker devices
ind_WW = (3+num_servers):(3+2*num_servers-1) # WriteWorker devices

predicted <- list()
predicted$type <- "predicted"
predicted$tps_mean <- sum(mva$X[1:2,1])
predicted$mean_response_time_get <- sum((mva$R * mva$V)[1,])*1000
predicted$mean_response_time_set <- sum((mva$R * mva$V)[2,])*1000
predicted$mean_response_time <-
(1 - prop_writes) * predicted$mean_response_time_get +
prop_writes / 100 * predicted$mean_response_time_set
predicted$rt_rw <- sum((mva$R * mva$V)[,ind_RW])*1000
predicted$rt_ww <- sum((mva$R * mva$V)[,c(ind_WW)])*1000

# ---- Actual results ----
tps_get <- (1-prop_writes) * mss$tps_mean # TODO this is an estimate -- could get precise!
tps_set <- prop_writes * mss$tps_mean
actual <- as.list(mss)
actual$rt_rw <- mean(requests_get$timeReturned-requests_get$timeEnqueued)
actual$rt_ww <- mean(requests_set$timeReceived-requests_set$timeEnqueued)



# ---- Analysis ----

comparison <- as.data.frame(actual) %>%
select(-std_response_time) %>%
rbind(as.data.frame(predicted)) %>%
mutate(servers=num_servers, threads=num_threads, clients=num_clients,
writes=perc_writes, replication=num_replication,
repetition=num_repetition)
comparison

# Time breakdown: actual vs predicted
data1 <- comparison %>%
select(rt_rw, rt_ww, type) %>%
melt(id.vars=c("type"))

ggplot(data1, aes(x=type, y=value, fill=type)) +
geom_bar(stat="identity") +
facet_wrap(~variable) +
asl_theme

0 comments on commit 090d9ff

Please sign in to comment.