From 5ac211f7d83acf3248ef46dc6e0f716ff7fc664b Mon Sep 17 00:00:00 2001 From: taivop Date: Tue, 6 Dec 2016 12:07:09 +0100 Subject: [PATCH] working on #170, also #175 --- report/milestone3.tex | 16 ++++++++++- scripts/r/ms3_common.r | 64 ++++++++++++++++++++++++++++++++++++++++++ scripts/r/part1_mm1.r | 34 ++++++++++++++++++++-- 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/report/milestone3.tex b/report/milestone3.tex index a80f129..0ad332c 100644 --- a/report/milestone3.tex +++ b/report/milestone3.tex @@ -81,11 +81,25 @@ \section{System as One Unit}\label{sec:system-one-unit} \todo{mention where data came from (new trace from MS2)} -problems: assumption that arrival rate is independent doesn't hold (closed system => memaslap sends new request as soon as it receives response) +book: "Unless explicitly specified, the queues are defined as having infinite buffer capacity, infinite population size, and an FCFS service discipline." + +book: "For example, the number of jobs in a queue with a single server and individual arrivals (not bulk arrivals) can be represented as a birth-death process" => we have birth-death process! + +book about M/M/1 queues: "It is assumed that the interarrival times and the service times are exponentially distributed and there is only one server. There are no buffer or population size limitations and the service discipline is FCFS." + +problems: assumption that arrival rate is i.i.d doesn't hold (closed system => memaslap sends new request as soon as it receives response) took service rate to be max of throughput and arrival rate as mean of throughput + +Once I have parameters, calculate: +\begin{itemize} + \item mean number of jobs in system and queue, using Little's law (Ch30.2) + \item distribution of number of jobs in system and queue +\end{itemize} + + \clearpage % -------------------------------------------------------------------------------- % -------------------------------------------------------------------------------- diff --git a/scripts/r/ms3_common.r b/scripts/r/ms3_common.r index 2890e96..6bb9318 100644 --- a/scripts/r/ms3_common.r +++ b/scripts/r/ms3_common.r @@ -34,4 +34,68 @@ file_to_df <- function(file_path, sep=";") { result <- data.frame() } return(result) +} + + +get_service_and_queue_distributions <- function(requests2) { + + total_timestamps <- c() + queue_timestamps <- c() + service_timestamps <- c() + for(i in 1:nrow(requests2)) { + if(i %% 1000 == 0) { + print(paste0("At row ", i, " out of ", nrow(requests2))) + } + row <- requests2[i,] + total_expanded <- seq(row$timeEnqueued, row$timeReturned, 1) + queue_expanded <- seq(row$timeEnqueued, row$timeDequeued, 1) + service_expanded <- seq(row$timeDequeued, row$timeReturned, 1) + total_timestamps <- append(total_timestamps, total_expanded) + queue_timestamps <- append(queue_timestamps, queue_expanded) + service_timestamps <- append(service_timestamps, service_expanded) + } + + total_counts <- data.frame(timestamp=total_timestamps) %>% + group_by(timestamp) %>% + summarise(num_elements=n()) + zeros <- data.frame(timestamp=seq(0, max(total_counts$timestamp), 1)) + total_counts <- total_counts %>% + full_join(zeros, by=c("timestamp")) %>% + mutate(num_elements=ifelse(is.na(num_elements), 0, num_elements)) %>% + group_by(num_elements) %>% + summarise(count=n()) + + queue_counts <- data.frame(timestamp=queue_timestamps) %>% + group_by(timestamp) %>% + summarise(num_elements=n()) + zeros <- data.frame(timestamp=seq(0, max(queue_counts$timestamp), 1)) + queue_counts <- queue_counts %>% + full_join(zeros, by=c("timestamp")) %>% + mutate(num_elements=ifelse(is.na(num_elements), 0, num_elements)) %>% + group_by(num_elements) %>% + summarise(count=n()) + + service_counts <- data.frame(timestamp=service_timestamps) %>% + group_by(timestamp) %>% + summarise(num_elements=n()) + zeros <- data.frame(timestamp=seq(0, max(service_counts$timestamp), 1)) + service_counts <- service_counts %>% + full_join(zeros, by=c("timestamp")) %>% + mutate(num_elements=ifelse(is.na(num_elements), 0, num_elements)) %>% + group_by(num_elements) %>% + summarise(count=n()) + + counts <- queue_counts %>% + full_join(service_counts, by=c("num_elements")) %>% + rename(queue=count.x, service=count.y) %>% + full_join(total_counts, by=c("num_elements")) %>% + rename(total=count) %>% + mutate(queue=ifelse(is.na(queue), 0, queue), + service=ifelse(is.na(service), 0, service), + total=ifelse(is.na(total), 0, total)) %>% + mutate(queue=queue/sum(queue), + service=service/sum(service), + total=total/sum(total)) + + return(counts) } \ No newline at end of file diff --git a/scripts/r/part1_mm1.r b/scripts/r/part1_mm1.r index c39fe2f..442c0c9 100644 --- a/scripts/r/part1_mm1.r +++ b/scripts/r/part1_mm1.r @@ -41,13 +41,41 @@ print(paste0("Traffic intensity: ", round(traffic_intensity, digits=2))) # ---- Predictions ---- predicted = list() -actual = list() +predicted$type <- "predicted" predicted$mean_num_jobs_in_system <- traffic_intensity / (1-traffic_intensity) +predicted$mean_num_jobs_in_queue <- traffic_intensity^2 / (1-traffic_intensity) predicted$utilisation <- 1 - traffic_intensity -predicted$mean_response_time <- 1 / (service_rate) / (1 - traffic_intensity) +predicted$mean_response_time <- 1 / (service_rate) / (1 - traffic_intensity) * 1000 # ms predicted$response_time_q50 <- predicted$mean_response_time * log(100 / (100-50)) predicted$response_time_q95 <- predicted$mean_response_time * log(100 / (100-95)) -print(predicted) +# ---- Actual results ---- +actual = list() + +# Number of jobs in system +time_zero <- min(requests$timeCreated) +N_SAMPLES <- 5000 +requests2 <- requests %>% + select(timeEnqueued, timeDequeued, timeReturned) %>% + mutate(timeEnqueued=timeEnqueued-time_zero, + timeDequeued=timeDequeued-time_zero, + timeReturned=timeReturned-time_zero) %>% + top_n(N_SAMPLES, wt=desc(timeEnqueued)) + +distributions <- get_service_and_queue_distributions(requests2) +means <- distributions %>% + summarise(queue=sum(num_elements * queue), + service=sum(num_elements * service), + total=sum(num_elements * total)) + +response_times <- requests$timeReturned - requests$timeEnqueued +actual$type <- "actual" +actual$mean_num_jobs_in_system <- means$total +actual$mean_num_jobs_in_queue <- means$queue +actual$utilisation <- 1 - (distributions %>% filter(num_elements==0))$total +actual$mean_response_time <- mean(response_times) +actual$response_time_q50 <- quantile(response_times, probs=c(0.5)) +actual$response_time_q95 <- quantile(response_times, probs=c(0.95)) +comparison <- rbind(data.frame(predicted), data.frame(actual))