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

Commit

Permalink
working on #170, also #175
Browse files Browse the repository at this point in the history
  • Loading branch information
taivop committed Dec 6, 2016
1 parent 7e9eac9 commit 5ac211f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
16 changes: 15 additions & 1 deletion report/milestone3.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
% --------------------------------------------------------------------------------
% --------------------------------------------------------------------------------
Expand Down
64 changes: 64 additions & 0 deletions scripts/r/ms3_common.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
34 changes: 31 additions & 3 deletions scripts/r/part1_mm1.r
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 5ac211f

Please sign in to comment.