Skip to content

Commit

Permalink
ttfb queries (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
rviscomi authored Oct 29, 2019
1 parent 2baebd3 commit 11de06a
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sql/2019/07_Performance/07_07.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#standardSQL
# 07_07: TTFB distribution
SELECT
fast,
avg,
slow
FROM (
SELECT
ROUND(fast_ttfb * 100, 2) AS fast,
ROUND(avg_ttfb * 100, 2) AS avg,
ROUND(slow_ttfb * 100, 2) AS slow,
ROW_NUMBER() OVER (ORDER BY fast_ttfb DESC) AS row,
COUNT(0) OVER () AS n
FROM
`chrome-ux-report.materialized.metrics_summary`
WHERE
date = '2019-07-01' AND
fast_ttfb + avg_ttfb + slow_ttfb > 0
ORDER BY
fast DESC)
WHERE
MOD(row, CAST(FLOOR(n / 1000) AS INT64)) = 0
24 changes: 24 additions & 0 deletions sql/2019/07_Performance/07_07b.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#standardSQL
# 07_07b: TTFB desktop distribution
SELECT
fast,
avg,
slow
FROM (
SELECT
device,
ROUND(SAFE_DIVIDE(fast_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS fast,
ROUND(SAFE_DIVIDE(avg_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS avg,
ROUND(SAFE_DIVIDE(slow_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS slow,
ROW_NUMBER() OVER (ORDER BY fast_ttfb DESC) AS row,
COUNT(0) OVER () AS n
FROM
`chrome-ux-report.materialized.device_summary`
WHERE
yyyymm = '201907' AND
fast_ttfb + avg_ttfb + slow_ttfb > 0 AND
device = 'desktop'
ORDER BY
fast DESC)
WHERE
MOD(row, CAST(FLOOR(n / 1000) AS INT64)) = 0
24 changes: 24 additions & 0 deletions sql/2019/07_Performance/07_07c.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#standardSQL
# 07_07c: TTFB phone distribution
SELECT
fast,
avg,
slow
FROM (
SELECT
device,
ROUND(SAFE_DIVIDE(fast_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS fast,
ROUND(SAFE_DIVIDE(avg_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS avg,
ROUND(SAFE_DIVIDE(slow_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) * 100, 2) AS slow,
ROW_NUMBER() OVER (ORDER BY fast_ttfb DESC) AS row,
COUNT(0) OVER () AS n
FROM
`chrome-ux-report.materialized.device_summary`
WHERE
yyyymm = '201907' AND
fast_ttfb + avg_ttfb + slow_ttfb > 0 AND
device = 'phone'
ORDER BY
fast DESC)
WHERE
MOD(row, CAST(FLOOR(n / 1000) AS INT64)) = 0
11 changes: 11 additions & 0 deletions sql/2019/07_Performance/07_08.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#standardSQL
# 07_08: % fast TTFB using FCP-like thresholds
SELECT
ROUND(COUNTIF(fast_ttfb >= .9) * 100 / COUNT(0), 2) AS pct_fast_ttfb,
ROUND(COUNTIF(NOT(slow_ttfb >= .1) AND NOT(fast_ttfb >= .9)) * 100 / COUNT(0), 2) AS pct_avg_ttfb,
ROUND(COUNTIF(slow_ttfb >= .1) * 100 / COUNT(0), 2) AS pct_slow_ttfb
FROM
`chrome-ux-report.materialized.metrics_summary`
WHERE
date = '2019-07-01' AND
fast_ttfb + avg_ttfb + slow_ttfb > 0
21 changes: 21 additions & 0 deletions sql/2019/07_Performance/07_08b.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#standardSQL
# 07_08b: % fast TTFB by device
SELECT
device,
ROUND(COUNTIF(fast_ttfb >= .9) * 100 / COUNT(0), 2) AS pct_fast_ttfb,
ROUND(COUNTIF(NOT(slow_ttfb >= .1) AND NOT(fast_ttfb >= .9)) * 100 / COUNT(0), 2) AS pct_avg_ttfb,
ROUND(COUNTIF(slow_ttfb >= .1) * 100 / COUNT(0), 2) AS pct_slow_ttfb
FROM (
SELECT
device,
SAFE_DIVIDE(fast_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) AS fast_ttfb,
SAFE_DIVIDE(avg_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) AS avg_ttfb,
SAFE_DIVIDE(slow_ttfb, fast_ttfb + avg_ttfb + slow_ttfb) AS slow_ttfb
FROM
`chrome-ux-report.materialized.device_summary`
WHERE
yyyymm = '201907' AND
fast_ttfb + avg_ttfb + slow_ttfb > 0 AND
device IN ('desktop', 'phone'))
GROUP BY
device
23 changes: 23 additions & 0 deletions sql/2019/07_Performance/07_08c.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#standardSQL
# 07_08c: % fast TTFB by ECT
SELECT
speed,
ROUND(COUNTIF(fast_ttfb >= .9) * 100 / COUNT(0), 2) AS pct_fast_ttfb,
ROUND(COUNTIF(NOT(slow_ttfb >= .1) AND NOT(fast_ttfb >= .9)) * 100 / COUNT(0), 2) AS pct_avg_ttfb,
ROUND(COUNTIF(slow_ttfb >= .1) * 100 / COUNT(0), 2) AS pct_slow_ttfb
FROM (
SELECT
effective_connection_type.name AS speed,
ROUND(SAFE_DIVIDE(SUM(IF(bin.start < 200, bin.density, 0)), SUM(bin.density)), 4) AS fast_ttfb,
ROUND(SAFE_DIVIDE(SUM(IF(bin.start >= 200 AND bin.start < 1000, bin.density, 0)), SUM(bin.density)), 4) AS avg_ttfb,
ROUND(SAFE_DIVIDE(SUM(IF(bin.start >= 1000, bin.density, 0)), SUM(bin.density)), 4) AS slow_ttfb
FROM
`chrome-ux-report.all.201907`,
UNNEST(experimental.time_to_first_byte.histogram.bin) AS bin
GROUP BY
origin,
speed)
GROUP BY
speed
ORDER BY
pct_fast_ttfb DESC
Loading

0 comments on commit 11de06a

Please sign in to comment.