by Animats · 2y ago · 0 comments
I have a web site set up that way. An in-memory table in MySQL is used to handle queuing for a slow operation. The queuing system has some fairness. This works well enough that one site sent bogus requests for a month at a high rate, and it had no effect on actual users.
Fair queuing in SQL:
SELECT domain, requestor_ip_hash, rating_state_int, base_domain FROM ratingqueue AS rqueue
WHERE (rating_state_int = 3 OR rating_state_int = 4)
AND NOT EXISTS(SELECT * FROM ratingqueue
WHERE base_domain = rqueue.base_domain
AND (rating_state_int = 1 OR rating_state_int = 2))
ORDER BY rating_state_int, request_timestamp
LIMIT 1;Would love to hear your thoughts about this project: https://github.com/fluxninja/aperture