measure usage

This commit is contained in:
Brandon Thomas committed 2024-04-03 12:22:06 -04:00
1 parent da438ff79d
commit 70f9d3bce0
1 file changed
+52 -25
@@ -6,7 +6,8 @@
-- NB: Nevermind, there's no index on `created_at`
-- select count(*) from generic_inference_jobs where created_at > now() - interval 1 minute;
-- When the database is under contention, use this form to reduce the number of rows scanned
-- Bin histogram by (creator user, IP address) (including logged out)
-- NB: no index on ip, hence subquery
SELECT
maybe_creator_user_token,
users.username as maybe_creator_username,
@@ -32,32 +33,11 @@ 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
-- Bin histogram by creator user (including logged out)
-- NB: no index on ip, hence subquery
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,
maybe_creator_user_token,
count(*) as attempts
FROM (
SELECT
@@ -77,3 +57,50 @@ 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;
-- Bin histogram by IP (logged in and non-logged in
-- NB: no index on ip, hence subquery
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;
-- Bin histogram by non-logged in IP
-- NB: no index on ip, hence subquery
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
AND j.maybe_creator_user_token IS NULL
) as jobs
group by creator_ip_address
order by attempts desc;