LP#
1435494: set limits on Clark Kent's resource usage
Clark Kent can sometimes consume more RAM, swap space, or CPU
than is reasonable or productive. For example:
- a badly constructed query with multiple Cartesian joins may
never terminate, potentially tying up a Clark child process,
pegging a CPU on the database server, and/or causing significant
scratch disk usage on the database server keeping a snapshot alive.
- a query that returns a very large number of rows can cause a Clark
child to bloat, and in extreme cases cause a OOM on the server
running Clark.
- a report that asks for a chart of an unreasonably large number of
rows can peg a CPU on the Clark server as GD::Graph attempts to
compute sub-pixel graph elements.
In each of these cases, a requested report may never finish.
This patch adds the ability set set some limits on Clark. These
limits can be set either in opensrf.xml for the settings service
to distribute or via command-line switches to clark-kent.pl:
//reporter/setup/statement_timeout / --statement-timeout
Number of minutes to allow a report's underlying SQL query
to run before it gets cancelled. Default value is
60 minutes. If a report's query gets cancelled, the
error_text value will be set to a valid that indicates that
the allowed time was exceeded.
//reporter/setup/max_rows_for_charts / --max-rows-for-charts
Number of rows permitted in the query's output before
Clark Kent refuses to attempt to draw a graph. Default
value is 1,000 rows.
//reporter/setup/resultset_limit / --resultset-limit
If set, truncates the report's output to the specified
number of hits. Note that it will not be apparent
to a staff user if the report's output has been
truncated. Default value is unlimited.
This patch also adds the ability for the concurrency
to be set via an opensrf.xml setting (//reporter/setup/parallel).
If both a command-line switch and an opensrf.xml setting
are supplied, the value set in the command line takes
precedence.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>