[Labs-l] User query-guard for sql tasks gone wild
Hedonil
hedonil at action.ms
Tue May 6 13:26:38 UTC 2014
In relation to current events, sometimes sql-queries may go wild and
clog/block other task.
Especially endangered species are queries from web/user interfaces,
which can become quite unpredictable at some time.
For example
- PHP has a default timeout of 30 seconds for pure script execution
(wait conditions excluded),
- lighttpd has a default write-idle timeout of 360 seconds
- in some cases you'll receive a 504 proxy-(gateway)-timeout
- or the user cancels his webrequest in his browser
in all cases, it's pointless to wait for the result, as it will never be
shown, but the sql-query lives on.
Of course, better coding is the best solution, but some cases are hard
to predict / detect.
To address this issue, I wrote a script that guards the current
sql-queries on a per user basis and nukes 'em after a configurable timeout.
As commented in the script:
To avoid killing useful maintenance tasks, it'd be best to mark your
user/web-queries with a comment (/* foo */ ) to tell long running god
ones from bad ones. This can also be configured in the script.
The script is available here:
/shared/sample_scripts/query-guard.sh
or here
https://tools.wmflabs.org/tools-info/misc/query-guard.sh
-Hedonil
More information about the Labs-l
mailing list