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/10/13 08:06:50 UTC
incubator-kylin git commit: minor, show thread ID is bad query log
Repository: incubator-kylin
Updated Branches:
refs/heads/1.x-staging 573e4ad85 -> 6da058fc9
minor, show thread ID is bad query log
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/6da058fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/6da058fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/6da058fc
Branch: refs/heads/1.x-staging
Commit: 6da058fc96295a08385c7a722aa6eeb38d26d917
Parents: 573e4ad
Author: Li, Yang <ya...@ebay.com>
Authored: Tue Oct 13 14:06:40 2015 +0800
Committer: Li, Yang <ya...@ebay.com>
Committed: Tue Oct 13 14:06:40 2015 +0800
----------------------------------------------------------------------
.../kylin/rest/service/BadQueryDetector.java | 30 +++++++++++---------
.../rest/service/BadQueryDetectorTest.java | 2 +-
2 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6da058fc/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 d3315c0..e7ea8d1 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
@@ -55,8 +55,8 @@ public class BadQueryDetector extends Thread {
this.notifiers.add(new Notifier() {
@Override
- public void badQueryFound(String adj, int runningSec, String sql) {
- logger.info(adj + " query has been running " + runningSec + " seconds -- " + sql);
+ public void badQueryFound(String adj, int runningSec, String sql, Thread t) {
+ logger.info(adj + " query has been running " + runningSec + " seconds, (thread id 0x" + Long.toHexString(t.getId()) + ") -- " + sql);
}
});
}
@@ -65,10 +65,10 @@ public class BadQueryDetector extends Thread {
notifiers.add(notifier);
}
- private void notify(String adj, int runningSec, String sql) {
+ private void notify(String adj, int runningSec, String sql, Thread t) {
for (Notifier notifier : notifiers) {
try {
- notifier.badQueryFound(adj, runningSec, sql);
+ notifier.badQueryFound(adj, runningSec, sql, t);
} catch (Exception e) {
logger.error("", e);
}
@@ -76,11 +76,11 @@ public class BadQueryDetector extends Thread {
}
public interface Notifier {
- void badQueryFound(String adj, int runningSec, String sql);
+ void badQueryFound(String adj, int runningSec, String sql, Thread t);
}
-
+
public void queryStart(Thread thread, SQLRequest sqlRequest) {
- runningQueries.put(thread, new Entry(sqlRequest));
+ runningQueries.put(thread, new Entry(thread, sqlRequest));
}
public void queryEnd(Thread thread) {
@@ -88,10 +88,12 @@ public class BadQueryDetector extends Thread {
}
private class Entry implements Comparable<Entry> {
+ final Thread thread;
final SQLRequest sqlRequest;
final long startTime;
- Entry(SQLRequest sqlRequest) {
+ Entry(Thread thread, SQLRequest sqlRequest) {
+ this.thread = thread;
this.sqlRequest = sqlRequest;
this.startTime = System.currentTimeMillis();
}
@@ -123,12 +125,12 @@ public class BadQueryDetector extends Thread {
long now = System.currentTimeMillis();
ArrayList<Entry> entries = new ArrayList<Entry>(runningQueries.values());
Collections.sort(entries);
-
+
// 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());
+ notify("Slow", runningSec, e.sqlRequest.getSql(), e.thread);
} else {
break; // entries are sorted by startTime
}
@@ -137,21 +139,21 @@ public class BadQueryDetector extends Thread {
// report if low memory
if (getSystemAvailMB() < alertMB) {
logger.info("System free memory less than " + alertMB + " MB. " + entries.size() + " queries running.");
-
+
for (Map.Entry<Thread, Entry> mapEntry : runningQueries.entrySet()) {
Entry e = mapEntry.getValue();
int duration = (int) ((now - e.startTime) / 1000);
if (duration > killRunningSec) {
- notify("Kill", duration, e.sqlRequest.getSql());
+ notify("Kill", duration, e.sqlRequest.getSql(), e.thread);
Thread queryThread = mapEntry.getKey();
killQueryThread(queryThread);
} else {
- notify("Low mem", duration, e.sqlRequest.getSql());
+ notify("Low mem", duration, e.sqlRequest.getSql(), e.thread);
}
}
}
}
-
+
private void killQueryThread(Thread thread) {
thread.interrupt();
}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6da058fc/server/src/test/java/org/apache/kylin/rest/service/BadQueryDetectorTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/kylin/rest/service/BadQueryDetectorTest.java b/server/src/test/java/org/apache/kylin/rest/service/BadQueryDetectorTest.java
index d7e8ba9..5cf7f51 100644
--- a/server/src/test/java/org/apache/kylin/rest/service/BadQueryDetectorTest.java
+++ b/server/src/test/java/org/apache/kylin/rest/service/BadQueryDetectorTest.java
@@ -38,7 +38,7 @@ public class BadQueryDetectorTest {
BadQueryDetector badQueryDetector = new BadQueryDetector(alertRunningSec * 1000, alertMB, alertRunningSec, alertRunningSec * 5);
badQueryDetector.registerNotifier(new BadQueryDetector.Notifier() {
@Override
- public void badQueryFound(String adj, int runningSec, String sql) {
+ public void badQueryFound(String adj, int runningSec, String sql, Thread t) {
alerts.add(new String[] { adj, sql });
}
});