You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2015/09/11 09:33:27 UTC
incubator-kylin git commit: minor,
enhance BadQueryDetector to report slow query at realtime
Repository: incubator-kylin
Updated Branches:
refs/heads/1.x-staging 44309fed9 -> 876079b51
minor, enhance BadQueryDetector to report slow query at realtime
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/876079b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/876079b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/876079b5
Branch: refs/heads/1.x-staging
Commit: 876079b516d4fcd193815a742612186409736021
Parents: 44309fe
Author: Li, Yang <ya...@ebay.com>
Authored: Fri Sep 11 15:33:14 2015 +0800
Committer: Li, Yang <ya...@ebay.com>
Committed: Fri Sep 11 15:33:14 2015 +0800
----------------------------------------------------------------------
.../kylin/rest/service/BadQueryDetector.java | 29 +++++++++++---------
1 file changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/876079b5/server/src/main/java/org/apache/kylin/rest/service/BadQueryDetector.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/service/BadQueryDetector.java b/server/src/main/java/org/apache/kylin/rest/service/BadQueryDetector.java
index 32410f4..5f5b247 100644
--- a/server/src/main/java/org/apache/kylin/rest/service/BadQueryDetector.java
+++ b/server/src/main/java/org/apache/kylin/rest/service/BadQueryDetector.java
@@ -81,14 +81,7 @@ public class BadQueryDetector extends Thread {
}
public void queryEnd(Thread thread) {
- Entry e = runningQueries.remove(thread);
-
- if (e != null) {
- int runningSec = (int) ((System.currentTimeMillis() - e.startTime) / 1000);
- if (runningSec >= alertRunningSec) {
- notify("Slow", runningSec, e.sqlRequest.getSql());
- }
- }
+ runningQueries.remove(thread);
}
private class Entry implements Comparable<Entry> {
@@ -124,18 +117,28 @@ public class BadQueryDetector extends Thread {
}
private void detectBadQuery() {
+ long now = System.currentTimeMillis();
+ ArrayList<Entry> entries = new ArrayList<Entry>(runningQueries.values());
+ Collections.sort(entries);
+
+ // report if low memory
if (getSystemAvailMB() < alertMB) {
- ArrayList<Entry> entries = new ArrayList<Entry>(runningQueries.values());
- Collections.sort(entries);
-
logger.info("System free memory less than " + alertMB + " MB. " + entries.size() + " queries running.");
- long now = System.currentTimeMillis();
-
for (int i = 0; i < entries.size(); i++) {
Entry e = entries.get(i);
notify("Low mem", (int) ((now - e.startTime) / 1000), e.sqlRequest.getSql());
}
}
+
+ // report if query running long
+ for (Entry e : entries) {
+ int runningSec = (int) ((now - e.startTime) / 1000);
+ if (runningSec >= alertRunningSec) {
+ notify("Slow", runningSec, e.sqlRequest.getSql());
+ } else {
+ break; // entries are sorted by startTime
+ }
+ }
}
public static final int ONE_MB = 1024 * 1024;