Skip to content

Commit

Permalink
Implement Elasticsearch query timeout.
Browse files Browse the repository at this point in the history
There's already Faraday or rack-timeout timeouts that will kick in and
kill the web request, but slow-running Elasticsearch queries from the
admin could run indefinitely inside Elasticsearch. This could compound
performance problems, since the admin interface would timeout, but
slow-running Elasticsearch queries could continue piling up in the
background.

We should make this timeout more configurable and try to better align
the Faraday timeout and rack-timeout (which now I'm not sure is even
working), but this is a quick fix to at least prevent background queries
from piling up and impacting system performance.
  • Loading branch information
GUI committed Jan 27, 2017
1 parent 6afb022 commit 6b1187d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def generate_summary
# This query can take a long time to run against PrestoDB, so set a long
# timeout. But since we're only delivering cached results and refreshing
# periodically in the background, this long timeout should be okay.
:query_timeout => "20m",
:query_timeout => 20 * 60, # 20 minutes
})

# Try to ignore some of the baseline monitoring traffic. Only include
Expand Down
2 changes: 2 additions & 0 deletions src/api-umbrella/web-app/app/models/log_search/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def initialize(options = {})
@end_time = Time.zone.now
end

@options[:query_timeout] ||= 90

@interval = options[:interval]
@region = options[:region]
@query = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def initialize(options = {})
:ignore_unavailable => "missing",
:allow_no_indices => true,
}

if(@options[:query_timeout])
@query_options[:timeout] = "#{@options[:query_timeout]}s"
end
end

def result
Expand All @@ -52,6 +56,10 @@ def result
query_options[:body].delete(:aggregations)
end
raw_result = @client.search(query_options)
if(raw_result["timed_out"])
# Don't return partial results.
raise "Elasticsearch request timed out"
end
@result = LogResult.factory(self, raw_result)
end

Expand Down
2 changes: 1 addition & 1 deletion src/api-umbrella/web-app/app/models/log_search/kylin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute_presto(sql)
req.headers["X-Presto-Catalog"] = "hive"
req.headers["X-Presto-Schema"] = "default"
if(@options[:query_timeout])
req.headers["X-Presto-Session"] = "query_max_run_time=#{@options[:query_timeout]}"
req.headers["X-Presto-Session"] = "query_max_run_time=#{@options[:query_timeout]}s"
end
req.body = sql
end
Expand Down

0 comments on commit 6b1187d

Please sign in to comment.