Skip to content

Commit 6b1187d

Browse files
committed
Implement Elasticsearch query timeout.
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.
1 parent 6afb022 commit 6b1187d

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/api-umbrella/web-app/app/controllers/api/v0/analytics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def generate_summary
103103
# This query can take a long time to run against PrestoDB, so set a long
104104
# timeout. But since we're only delivering cached results and refreshing
105105
# periodically in the background, this long timeout should be okay.
106-
:query_timeout => "20m",
106+
:query_timeout => 20 * 60, # 20 minutes
107107
})
108108

109109
# Try to ignore some of the baseline monitoring traffic. Only include

src/api-umbrella/web-app/app/models/log_search/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def initialize(options = {})
3131
@end_time = Time.zone.now
3232
end
3333

34+
@options[:query_timeout] ||= 90
35+
3436
@interval = options[:interval]
3537
@region = options[:region]
3638
@query = {}

src/api-umbrella/web-app/app/models/log_search/elastic_search.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def initialize(options = {})
3737
:ignore_unavailable => "missing",
3838
:allow_no_indices => true,
3939
}
40+
41+
if(@options[:query_timeout])
42+
@query_options[:timeout] = "#{@options[:query_timeout]}s"
43+
end
4044
end
4145

4246
def result
@@ -52,6 +56,10 @@ def result
5256
query_options[:body].delete(:aggregations)
5357
end
5458
raw_result = @client.search(query_options)
59+
if(raw_result["timed_out"])
60+
# Don't return partial results.
61+
raise "Elasticsearch request timed out"
62+
end
5563
@result = LogResult.factory(self, raw_result)
5664
end
5765

src/api-umbrella/web-app/app/models/log_search/kylin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def execute_presto(sql)
4545
req.headers["X-Presto-Catalog"] = "hive"
4646
req.headers["X-Presto-Schema"] = "default"
4747
if(@options[:query_timeout])
48-
req.headers["X-Presto-Session"] = "query_max_run_time=#{@options[:query_timeout]}"
48+
req.headers["X-Presto-Session"] = "query_max_run_time=#{@options[:query_timeout]}s"
4949
end
5050
req.body = sql
5151
end

0 commit comments

Comments
 (0)