show active threads in metrics

This commit is contained in:
Athou
2013-07-05 09:52:23 +02:00
parent 5530c5fd7e
commit c388e726fe
4 changed files with 28 additions and 9 deletions

View File

@@ -17,7 +17,8 @@ public class FeedRefreshExecutor {
private ThreadPoolExecutor pool; private ThreadPoolExecutor pool;
private LinkedBlockingDeque<Runnable> queue; private LinkedBlockingDeque<Runnable> queue;
public FeedRefreshExecutor(final String poolName, int threads, int queueCapacity) { public FeedRefreshExecutor(final String poolName, int threads,
int queueCapacity) {
this.poolName = poolName; this.poolName = poolName;
pool = new ThreadPoolExecutor(threads, threads, 0, pool = new ThreadPoolExecutor(threads, threads, 0,
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
@@ -46,7 +47,8 @@ public class FeedRefreshExecutor {
queue.put(r); queue.put(r);
} }
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
log.error(poolName + " interrupted while waiting for queue.", e1); log.error(poolName
+ " interrupted while waiting for queue.", e1);
} }
} }
}); });
@@ -60,6 +62,10 @@ public class FeedRefreshExecutor {
return queue.size(); return queue.size();
} }
public int getActiveCount() {
return pool.getActiveCount();
}
public static interface Task extends Runnable { public static interface Task extends Runnable {
boolean isUrgent(); boolean isUrgent();
} }
@@ -70,7 +76,9 @@ public class FeedRefreshExecutor {
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("{} interrupted while waiting for threads to finish.", poolName); log.error(
"{} interrupted while waiting for threads to finish.",
poolName);
} }
} }
} }

View File

@@ -185,4 +185,8 @@ public class FeedRefreshUpdater {
return pool.getQueueSize(); return pool.getQueueSize();
} }
public int getActiveCount() {
return pool.getActiveCount();
}
} }

View File

@@ -53,7 +53,8 @@ public class FeedRefreshWorker {
ApplicationSettings settings = applicationSettingsService.get(); ApplicationSettings settings = applicationSettingsService.get();
int threads = settings.getBackgroundThreads(); int threads = settings.getBackgroundThreads();
log.info("Creating refresh worker pool with {} threads", threads); log.info("Creating refresh worker pool with {} threads", threads);
pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads, 20 * threads); pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads,
20 * threads);
} }
@PreDestroy @PreDestroy
@@ -64,11 +65,15 @@ public class FeedRefreshWorker {
public void updateFeed(Feed feed) { public void updateFeed(Feed feed) {
pool.execute(new FeedTask(feed)); pool.execute(new FeedTask(feed));
} }
public int getQueueSize(){ public int getQueueSize() {
return pool.getQueueSize(); return pool.getQueueSize();
} }
public int getActiveCount() {
return pool.getActiveCount();
}
private class FeedTask implements Task { private class FeedTask implements Task {
private Feed feed; private Feed feed;
@@ -125,7 +130,8 @@ public class FeedRefreshWorker {
feedRefreshUpdater.updateFeed(feed, entries); feedRefreshUpdater.updateFeed(feed, entries);
} catch (NotModifiedException e) { } catch (NotModifiedException e) {
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage()); log.debug("Feed not modified : {} - {}", feed.getUrl(),
e.getMessage());
Date disabledUntil = null; Date disabledUntil = null;
if (applicationSettingsService.get().isHeavyLoad()) { if (applicationSettingsService.get().isHeavyLoad()) {

View File

@@ -236,7 +236,9 @@ public class AdminREST extends AbstractResourceREST {
if (backlog) { if (backlog) {
map.put("backlog", taskGiver.getUpdatableCount()); map.put("backlog", taskGiver.getUpdatableCount());
} }
map.put("http_active", feedRefreshWorker.getActiveCount());
map.put("http_queue", feedRefreshWorker.getQueueSize()); map.put("http_queue", feedRefreshWorker.getQueueSize());
map.put("database_active", feedRefreshUpdater.getActiveCount());
map.put("database_queue", feedRefreshUpdater.getQueueSize()); map.put("database_queue", feedRefreshUpdater.getQueueSize());
map.put("cache", metricsBean.getCacheStats()); map.put("cache", metricsBean.getCacheStats());
@@ -249,8 +251,7 @@ public class AdminREST extends AbstractResourceREST {
Map<String, Long> map = Maps.newHashMap(); Map<String, Long> map = Maps.newHashMap();
map.put("feeds_without_subscriptions", map.put("feeds_without_subscriptions",
cleaner.cleanFeedsWithoutSubscriptions()); cleaner.cleanFeedsWithoutSubscriptions());
map.put("entries_without_feeds", map.put("entries_without_feeds", cleaner.cleanEntriesWithoutFeeds());
cleaner.cleanEntriesWithoutFeeds());
return Response.ok(map).build(); return Response.ok(map).build();
} }