Skip to content

around: check the query's time limit while filtering candidates - #12

Open
cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:around-health-check
Open

cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:around-health-check

Conversation

@cldellow

Copy link
Copy Markdown

Query timeouts are enforced after filters are applied:

for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
it != constraints.end(); ++it)
(*it)->filter(rman, into);
set_progress(6);
rman.health_check(*this);

However, some filters can be quite expensive, depending on their inputs. The around filter is such an example.

This PR enforces timeouts more promptly by calling health_check periodically during the around filter.

health_check itself is cheap and does not impact query runtime.

On the Geofabrik Nova Scotia export, this query:

[timeout:10][out:csv(::count)];
rel(id:5429184,7081003,8322255,9270031,10270951,13448043)->.s0;
.s0 <<->.s2;
way(around.s2:0)[!"height"];
out count;

This PR: times out after 11 seconds with runtime error: Query timed out in "query" at line 1 after 11 seconds.

Current master: the timeout never fires. Instead, a backstop calculated here and enforced here fires after 80 seconds, and the osm3s_query process is killed.

The backstop is 2*timeout + 60, so with the default timeout of 180 seconds, a query can run for an extra 4 minutes before being killed.

In all cases, such a delayed timeout would have eventually failed the query anyway. This change just causes it to fail sooner, so the CPU can be relinquished for useful work.

@cldellow

Copy link
Copy Markdown
Author

Other PRs will hopefully render this moot by just speeding up the around filter's most egregious cases -- but in the interim, this is a stopgap that's hopefully easier to review/merge.

That said, I don't know if this will actually help production in the near term.

Two signs that would suggest it's helping (assuming the query mix is more or less consistent day to day):

  • an increase in Timeout: logs in database.log (suggesting the backstop is being hit less often)
  • the number of Timeout: logs stays the same, but the average time reported decreases (suggesting that the timeout was being enforced before, but is now being enforced more promptly)

I think grepping the log for read_aborted of process would also give a sense of how often queries are getting killed by the backstop as opposed to the timeout.

@cldellow
cldellow force-pushed the around-health-check branch from 546cd29 to db29404 Compare November 24, 2026 18:59
@cldellow

Copy link
Copy Markdown
Author

Oops, the commits here aren't squashed yet. Will fix that up later tonight.

The expensive around filters (filter_nodes_expensive,
filter_ways_expensive, filter_relations_expensive) ran to completion
before the next health check. A slow around therefore kept a CPU busy
long after the query's [timeout:] had passed, only to fail with the
timeout error once it finished.

A Periodic_Health_Check now calls rman.health_check after every 64k
units of work, so the query stops with the usual timeout error soon
after its time is up. A unit is about one comparison of a candidate's
point or segment with a point or segment of the input: is_inside on a
way geometry now takes the check and ticks it for every point and
segment it tests, also for the ways of candidate relations. Counting
candidates alone isn't enough, because a single long way, such as a
power line, tested against a large input can take seconds.

Queries that finish within their limits return the same results as
before.

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
@cldellow
cldellow force-pushed the around-health-check branch from db29404 to bafc862 Compare November 24, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants