-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
145 lines (124 loc) · 5.29 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
library(shiny)
library(scales)
library(ggplot2)
library(Cairo)
library(queueing)
rho <- seq (0.01, 0.99, by = 0.01)
nPoints <- length(rho)
yMax <- 16
yBreaks <- seq(0, 128, by = 2)
yLabels <- sprintf('%sx', yBreaks)
xBreaks <- seq(0, 1, by = 0.2)
formatYLabel <- function(l) {
sprintf('%sx', l)
}
shinyServer(
function(input, output) {
# React to changes in the Number of Servers
#
N <- reactive({ input$nServers })
# Create the queue networks for each of the three systems
#
gsQueue <- reactive({ QueueingModel(NewInput.MM1(lambda = rho, mu = 1)) })
btQueue <- reactive({ QueueingModel(NewInput.MMC(lambda = rho * N(), mu = 1, c = N())) })
ssQueue <- reactive({ QueueingModel(NewInput.MM1(lambda = rho * N() ,mu = 1 * N())) })
# Watch for zoom actions in chart
#
selectedRange <- reactiveValues(x = c(0, 1),
y = c(0, yMax))
observeEvent(
input$rspTimeChart.dblClick, {
b <- input$rspTimeChart.brush
if (!is.null(b)) {
selectedRange$x <- c(b$xmin, b$xmax)
selectedRange$y <- c(b$ymin, b$ymax)
} else {
selectedRange$x <- c(0, 1)
selectedRange$y <- c(0, yMax)
}
}
)
# Chart Response Time
#
output$rspTimeChart<- renderPlot({
rspData <-
rbind (data.frame(util= rho, rsp = W(gsQueue()), qtype = 'Grocery Store'),
data.frame(util= rho, rsp = W(btQueue()), qtype = 'Bank Teller'),
data.frame(util= rho, rsp = W(ssQueue()), qtype = 'Super Server')
)
g <-
ggplot(
data=rspData,
aes(y = rsp,
x = util,
colour = qtype)) +
ggtitle(expression(paste('Response time ',italic('hockey sticks'),' as load increases'))) +
labs(y = 'Relative Response Time',
x = 'System Utilization',
colour = '') +
#geom_point() +
geom_line(size = 0.75) +
coord_cartesian(xlim = selectedRange$x,
ylim = selectedRange$y) +
# scale_y_continuous(labels = yLabels, breaks = yBreaks) +
scale_y_continuous(labels = formatYLabel) +
scale_x_continuous(labels = percent, breaks = xBreaks) +
theme(plot.title = element_text(size = 16, hjust = 0),
axis.title.x = element_text(size = 12, colour = 'grey50'),
axis.text.x = element_text(size = 12, colour = 'grey50'),
axis.title.y = element_text(size = 12, colour = 'grey50'),
axis.text.y = element_text(size = 12, colour = 'grey50'),
legend.position = 'top',
legend.title = element_blank(),
legend.text = element_text(size = 14),
legend.key = element_rect(fill = 'transparent'),
legend.background = element_rect(fill = 'transparent')
)
g
})
# Chart Response Time Componenets
#
output$waitTimeChart<- renderPlot({
df <- rbind (
data.frame(util = rho, rspcat = 'Wait Time', time = Wq(gsQueue()), qtype = 'Grocery Store'),
data.frame(util = rho, rspcat = 'Wait Time', time = Wq(btQueue()), qtype = 'Bank Teller'),
data.frame(util = rho, rspcat = 'Wait Time', time = Wq(ssQueue()), qtype = 'Super Server'),
data.frame(util = rho, rspcat = 'Service Time', time = rep(1, nPoints), qtype = 'Grocery Store'),
data.frame(util = rho, rspcat = 'Service Time', time = rep(1, nPoints), qtype = 'Bank Teller'),
data.frame(util = rho, rspcat = 'Service Time', time = rep(1/N(), nPoints), qtype = 'Super Server')
)
g <-
ggplot(
data=df,
aes(y = time,
x = util,
colour = rspcat
)) +
facet_wrap(~ qtype, ncol = 1) +
ggtitle(paste('Wait time dominates as load increases\nAt wait = service, response has doubled')) +
labs(y = 'Relative Response Time',
x = 'System Utilization',
colour = '') +
geom_line(size = 0.75) +
coord_cartesian(xlim = selectedRange$x,
ylim = selectedRange$y) +
# scale_y_continuous(labels = yLabels, breaks = yBreaks) +
scale_y_continuous(labels = formatYLabel) +
scale_x_continuous(labels = percent, breaks = xBreaks) +
guides(fill = guide_legend(reverse = TRUE)) +
theme(plot.title = element_text(size = 16, hjust = 0),
axis.title.x = element_text(size = 12, colour = 'grey50'),
axis.text.x = element_text(size = 12, colour = 'grey50'),
axis.title.y = element_text(size = 12, colour = 'grey50'),
axis.text.y = element_text(size = 12, colour = 'grey50'),
legend.position = 'top',
legend.title = element_blank(),
legend.text = element_text(size = 12, colour = 'grey50'),
legend.background = element_rect(fill = 'transparent'),
legend.key = element_rect(fill = 'transparent'),
strip.text = element_text(size = 14)
)
g
})
}
)