mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
show active threads in metrics
This commit is contained in:
@@ -17,7 +17,8 @@ public class FeedRefreshExecutor {
|
||||
private ThreadPoolExecutor pool;
|
||||
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;
|
||||
pool = new ThreadPoolExecutor(threads, threads, 0,
|
||||
TimeUnit.MILLISECONDS,
|
||||
@@ -46,7 +47,8 @@ public class FeedRefreshExecutor {
|
||||
queue.put(r);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
|
||||
public int getActiveCount() {
|
||||
return pool.getActiveCount();
|
||||
}
|
||||
|
||||
public static interface Task extends Runnable {
|
||||
boolean isUrgent();
|
||||
}
|
||||
@@ -70,7 +76,9 @@ public class FeedRefreshExecutor {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("{} interrupted while waiting for threads to finish.", poolName);
|
||||
log.error(
|
||||
"{} interrupted while waiting for threads to finish.",
|
||||
poolName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,4 +185,8 @@ public class FeedRefreshUpdater {
|
||||
return pool.getQueueSize();
|
||||
}
|
||||
|
||||
public int getActiveCount() {
|
||||
return pool.getActiveCount();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ public class FeedRefreshWorker {
|
||||
ApplicationSettings settings = applicationSettingsService.get();
|
||||
int threads = settings.getBackgroundThreads();
|
||||
log.info("Creating refresh worker pool with {} threads", threads);
|
||||
pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads, 20 * threads);
|
||||
pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads,
|
||||
20 * threads);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@@ -64,11 +65,15 @@ public class FeedRefreshWorker {
|
||||
public void updateFeed(Feed feed) {
|
||||
pool.execute(new FeedTask(feed));
|
||||
}
|
||||
|
||||
public int getQueueSize(){
|
||||
|
||||
public int getQueueSize() {
|
||||
return pool.getQueueSize();
|
||||
}
|
||||
|
||||
public int getActiveCount() {
|
||||
return pool.getActiveCount();
|
||||
}
|
||||
|
||||
private class FeedTask implements Task {
|
||||
|
||||
private Feed feed;
|
||||
@@ -125,7 +130,8 @@ public class FeedRefreshWorker {
|
||||
feedRefreshUpdater.updateFeed(feed, entries);
|
||||
|
||||
} catch (NotModifiedException e) {
|
||||
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage());
|
||||
log.debug("Feed not modified : {} - {}", feed.getUrl(),
|
||||
e.getMessage());
|
||||
|
||||
Date disabledUntil = null;
|
||||
if (applicationSettingsService.get().isHeavyLoad()) {
|
||||
|
||||
@@ -236,7 +236,9 @@ public class AdminREST extends AbstractResourceREST {
|
||||
if (backlog) {
|
||||
map.put("backlog", taskGiver.getUpdatableCount());
|
||||
}
|
||||
map.put("http_active", feedRefreshWorker.getActiveCount());
|
||||
map.put("http_queue", feedRefreshWorker.getQueueSize());
|
||||
map.put("database_active", feedRefreshUpdater.getActiveCount());
|
||||
map.put("database_queue", feedRefreshUpdater.getQueueSize());
|
||||
map.put("cache", metricsBean.getCacheStats());
|
||||
|
||||
@@ -249,8 +251,7 @@ public class AdminREST extends AbstractResourceREST {
|
||||
Map<String, Long> map = Maps.newHashMap();
|
||||
map.put("feeds_without_subscriptions",
|
||||
cleaner.cleanFeedsWithoutSubscriptions());
|
||||
map.put("entries_without_feeds",
|
||||
cleaner.cleanEntriesWithoutFeeds());
|
||||
map.put("entries_without_feeds", cleaner.cleanEntriesWithoutFeeds());
|
||||
return Response.ok(map).build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user