From d58725d6295996f10919ebdb47be5950ffac7fc8 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 24 Mar 2024 16:36:04 -0400 Subject: [PATCH] analysis: jobs by ip address --- .../generic_inference/jobs_by_ip_address.sql | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 _sql/analytics/generic_inference/jobs_by_ip_address.sql diff --git a/_sql/analytics/generic_inference/jobs_by_ip_address.sql b/_sql/analytics/generic_inference/jobs_by_ip_address.sql new file mode 100644 index 0000000000..58e2657ce9 --- /dev/null +++ b/_sql/analytics/generic_inference/jobs_by_ip_address.sql @@ -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;