-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlot cont
More file actions
60 lines (58 loc) · 3.52 KB
/
Slot cont
File metadata and controls
60 lines (58 loc) · 3.52 KB
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
It's challenging to pinpoint the exact moment of slot contention and the corresponding user/query directly within BigQuery. The INFORMATION_SCHEMA views provide valuable data about jobs, but they don't have a specific flag for "slot contention." However, we can use a combination of metrics and queries to identify potential contention periods and investigate further.
Here's a strategy combining SQL queries with external analysis in Excel:
1. Identify Potential Contention Periods
This query analyzes historical job data to find periods where slot utilization was high, suggesting possible contention:
SELECT
DATE(creation_time) AS execution_date,
EXTRACT(HOUR FROM creation_time) AS execution_hour,
AVG(total_slot_ms) AS avg_slot_ms,
COUNT(job_id) AS num_jobs
FROM
`region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
WHERE
creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY) AND CURRENT_TIMESTAMP()
AND project_id = 'your-project-id'
GROUP BY
execution_date,
execution_hour
ORDER BY
avg_slot_ms DESC;
* Explanation:
* We analyze job data from the last 7 days (adjust as needed).
* total_slot_ms indicates the slots consumed by a job. Higher values suggest more resource-intensive queries.
* Grouping by execution_date and execution_hour helps identify specific hours where slot usage was high.
* Ordering by avg_slot_ms DESC highlights periods with the highest average slot consumption.
2. Export to Excel and Visualize
* Export: Run the query in BigQuery and export the results to a CSV file.
* Excel Analysis:
* Open the CSV in Excel.
* Create a pivot table or chart to visualize avg_slot_ms and num_jobs over time (by execution_date and execution_hour).
* Look for spikes in avg_slot_ms or a high num_jobs – these might indicate contention periods.
3. Drill Down into Specific Periods (in BigQuery)
Once you've identified potential contention periods in Excel, use this query to get the details of jobs running during those times:
SELECT
job_id,
user_email,
query,
creation_time,
total_slot_ms,
error_result
FROM
`region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
WHERE
creation_time BETWEEN 'start_time' AND 'end_time' -- Replace with your identified time range
AND project_id = 'your-project-id'
ORDER BY
creation_time;
* Explanation:
* Replace 'start_time' and 'end_time' with the specific time range you identified in Excel.
* This query retrieves details like job_id, user_email, the actual query, and total_slot_ms for analysis.
4. Further Analysis and Refinement
* Correlate with Errors: Check the error_result column in the second query. Frequent errors during high slot usage periods can further indicate contention issues.
* Query Complexity: Analyze the query text for long-running or complex queries that might be contributing to contention.
* User Patterns: Identify specific users or teams consistently running resource-intensive queries during peak times.
Important Considerations:
* Reservation API: If you have BigQuery Reservations, incorporate reservation_id in your queries to analyze slot usage within specific reservations.
* Cloud Monitoring: Explore Cloud Monitoring for BigQuery to get more detailed metrics and set up alerts for potential contention.
* Query Optimization: Proactively optimize your queries to reduce slot consumption and minimize contention.
This approach provides a starting point for your analysis. You can refine these queries and your Excel analysis based on your specific needs and observations.