analysis: jobs by ip address

This commit is contained in:
Brandon Thomas committed 2024-03-24 16:36:04 -04:00
1 parent a6c7d757a4
commit d58725d629
1 file changed
+89
@@ -0,0 +1,89 @@
-- noinspection SqlDialectInspectionForFile
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlResolveForFile
select
maybe_creator_user_token,
users.username as maybe_creator_username,
creator_ip_address,
count(*) as attempts
from generic_inference_jobs as jobs
left outer join users
on users.token = jobs.maybe_creator_user_token
where status IN ('pending', 'started', 'complete_failure', 'attempt_failed')
and jobs.created_at > NOW() - INTERVAL 1 MINUTE
group by maybe_creator_user_token, maybe_creator_username, creator_ip_address
order by attempts desc;
-- When the database is under contention, use this form to reduce the number of rows scanned
SELECT
maybe_creator_user_token,
users.username as maybe_creator_username,
creator_ip_address,
count(*) as attempts
FROM (
SELECT
maybe_creator_user_token,
creator_ip_address
FROM (
SELECT maybe_creator_user_token,
creator_ip_address,
created_at
FROM generic_inference_jobs
ORDER BY id DESC
LIMIT 10000
) as j
WHERE j.created_at > NOW() - INTERVAL 30 MINUTE
) as jobs
LEFT OUTER JOIN users
ON users.token = jobs.maybe_creator_user_token
group by maybe_creator_user_token, maybe_creator_username, creator_ip_address
order by attempts desc;
-- When the database is under contention, use this form to reduce the number of rows scanned
SELECT
creator_ip_address,
count(*) as attempts
FROM (
SELECT
maybe_creator_user_token,
creator_ip_address
FROM (
SELECT maybe_creator_user_token,
creator_ip_address,
created_at
FROM generic_inference_jobs
ORDER BY id DESC
LIMIT 10000
) as j
WHERE j.created_at > NOW() - INTERVAL 30 MINUTE
) as jobs
group by creator_ip_address
order by attempts desc;
-- When the database is under contention, use this form to reduce the number of rows scanned
SELECT
maybe_creator_user_token,
users.username as maybe_creator_username,
count(*) as attempts
FROM (
SELECT
maybe_creator_user_token,
creator_ip_address
FROM (
SELECT maybe_creator_user_token,
creator_ip_address,
created_at
FROM generic_inference_jobs
ORDER BY id DESC
LIMIT 10000
) as j
WHERE j.created_at > NOW() - INTERVAL 30 MINUTE
) as jobs
LEFT OUTER JOIN users
ON users.token = jobs.maybe_creator_user_token
group by maybe_creator_user_token, maybe_creator_username
order by attempts desc;