-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother_minibatch_impls.py
61 lines (45 loc) · 2.01 KB
/
other_minibatch_impls.py
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
from typing import TYPE_CHECKING, Sequence, Tuple
import functools as ft
import pandas as pd
from livestats import livestats
if TYPE_CHECKING:
from serversim import UserGroup
def minibatch_resp_times_pandas1(time_resolution, grp):
# type: (float, UserGroup) -> Tuple[Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float]]
xys = (((svc_req.time_dict["submitted"]//time_resolution) * time_resolution,
svc_req.time_dict["completed"] - svc_req.time_dict["submitted"])
for (_, svc_req) in grp.svc_req_log
if svc_req.is_completed)
df = pd.DataFrame(xys, columns=["time", "resp_time"])
grouped = df.groupby("time")["resp_time"]
counts_ser = grouped.count()
ts = counts_ser.index.values
counts = counts_ser.values
means = grouped.mean().values
q_50 = grouped.quantile(.50).values
q_95 = grouped.quantile(.95).values
q_99 = grouped.quantile(.99).values
return ts, counts, means, q_50, q_95, q_99
def minibatch_resp_times_without_pandas(time_resolution, grp):
# type: (float, UserGroup) -> Tuple[Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float]]
quantiles = [0.5, 0.95, 0.99]
xys = ((int(svc_req.time_dict["submitted"]/time_resolution),
svc_req.time_dict["completed"] - svc_req.time_dict["submitted"])
for (_, svc_req) in grp.svc_req_log
if svc_req.is_completed)
def ffold(map_, p):
x, y = p
if x not in map_:
map_[x] = livestats.LiveStats(quantiles)
map_[x].add(y)
return map_
xlvs = ft.reduce(ffold, xys, dict())
xs = xlvs.keys()
xs.sort()
ts = [x*time_resolution for x in xs]
counts = [xlvs[x].count for x in xs]
means = [xlvs[x].average for x in xs]
q_50 = [xlvs[x].quantiles()[0] for x in xs]
q_95 = [xlvs[x].quantiles()[1] for x in xs]
q_99 = [xlvs[x].quantiles()[2] for x in xs]
return ts, counts, means, q_50, q_95, q_99