提交 5c68fba3 编写于 作者: Y youyong

modify the cat memory leak problem

上级 d45e72f9
......@@ -77,7 +77,8 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
.req(BucketManager.class, ReportDao.class));
all.add(C(CommonAnalyzer.class).is(PER_LOOKUP)//
.req(HostinfoDao.class));
.req(HostinfoDao.class)//
.req(BucketManager.class));
all.add(C(TopIpAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class));
......
......@@ -14,6 +14,7 @@ import com.dianping.cat.hadoop.dal.Hostinfo;
import com.dianping.cat.hadoop.dal.HostinfoDao;
import com.dianping.cat.message.spi.AbstractMessageAnalyzer;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.storage.BucketManager;
import com.site.dal.jdbc.DalException;
import com.site.lookup.annotation.Inject;
......@@ -24,11 +25,19 @@ public class CommonAnalyzer extends AbstractMessageAnalyzer<CommonReport> implem
@Inject
private HostinfoDao m_hostInfoDao;
@Inject
private BucketManager m_bucketManager;
@Override
public void doCheckpoint(boolean atEnd) {
//if (atEnd) {
if (atEnd) {
storeReport();
//}
}
try {
m_bucketManager.closeAllLogviewBuckets();
} catch (Exception e) {
m_logger.error("Close logviewbucket error", e);
}
}
private void storeReport() {
......@@ -38,7 +47,7 @@ public class CommonAnalyzer extends AbstractMessageAnalyzer<CommonReport> implem
for (String ip : ips) {
Hostinfo info = m_hostInfoDao.createLocal();
info.setDomain(domain);
info.setIp(ip);
try {
......
......@@ -130,6 +130,9 @@
<requirement>
<role>com.dianping.cat.hadoop.dal.HostinfoDao</role>
</requirement>
<requirement>
<role>com.dianping.cat.storage.BucketManager</role>
</requirement>
</requirements>
</component>
<component>
......
......@@ -6,12 +6,14 @@ import java.util.List;
import com.dianping.cat.message.spi.MessageTree;
public interface BucketManager {
public void closeAllLogviewBuckets();
public void closeBucket(Bucket<?> bucket);
public List<Bucket<MessageTree>> getLogviewBuckets(long timestamp,String excludeDomain) throws IOException;
public Bucket<MessageTree> getLogviewBucket(long timestamp, String domain) throws IOException;
public List<Bucket<MessageTree>> getLogviewBuckets(long timestamp, String excludeDomain) throws IOException;
public Bucket<MessageTree> getMessageBucket(long timestamp, String domain) throws IOException;
public Bucket<String> getReportBucket(long timestamp, String name) throws IOException;
......
......@@ -84,11 +84,11 @@ public class DefaultBucketManager extends ContainerHolder implements BucketManag
public List<Bucket<MessageTree>> getLogviewBuckets(long timestamp, String excludeDomain) throws IOException {
long t = timestamp - timestamp % (60 * 60 * 1000L);
List<Bucket<MessageTree>> buckets = new ArrayList<Bucket<MessageTree>>();
for (Bucket<?> bucket : m_map.values()) {
if (bucket instanceof LocalLogviewBucket) {
LocalLogviewBucket logview = (LocalLogviewBucket) bucket;
if (logview.getTimestamp() == t && !logview.getDomain().equals(excludeDomain)) {
buckets.add(logview);
}
......@@ -149,4 +149,22 @@ public class DefaultBucketManager extends ContainerHolder implements BucketManag
return String.format("Entry[type=%s,path=%s]", m_type, m_path);
}
}
@Override
public void closeAllLogviewBuckets() {
int hour = 60 * 60 * 1000;
long currentTimeMillis = System.currentTimeMillis();
long lastHour = currentTimeMillis - currentTimeMillis % hour - 2 * hour;
for (Bucket<?> bucket : m_map.values()) {
if (bucket instanceof LocalLogviewBucket) {
long timestamp = ((LocalLogviewBucket) bucket).getTimestamp();
if (timestamp < lastHour) {
LocalLogviewBucket logview = (LocalLogviewBucket) bucket;
closeBucket(logview);
}
}
}
}
}
......@@ -1566,32 +1566,32 @@
<implementation>com.dianping.cat.report.page.cache.Handler</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.report.page.cache.JspViewer</role>
<role>com.dianping.cat.hadoop.dal.DailyreportDao</role>
</requirement>
<requirement>
<role>com.dianping.cat.hadoop.dal.ReportDao</role>
<role>com.dianping.cat.report.task.event.EventMerger</role>
</requirement>
<requirement>
<role>com.dianping.cat.hadoop.dal.DailyreportDao</role>
<role>com.dianping.cat.report.page.model.spi.ModelService</role>
<role-hint>event</role-hint>
<field-name>m_eventService</field-name>
</requirement>
<requirement>
<role>com.dianping.cat.report.task.event.EventMerger</role>
<role>com.dianping.cat.report.page.cache.JspViewer</role>
</requirement>
<requirement>
<role>com.dianping.cat.report.task.transaction.TransactionMerger</role>
<role>com.dianping.cat.configuration.ServerConfigManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.configuration.ServerConfigManager</role>
<role>com.dianping.cat.hadoop.dal.ReportDao</role>
</requirement>
<requirement>
<role>com.dianping.cat.report.page.model.spi.ModelService</role>
<role-hint>transaction</role-hint>
<field-name>m_transactionService</field-name>
<role>com.dianping.cat.report.task.transaction.TransactionMerger</role>
</requirement>
<requirement>
<role>com.dianping.cat.report.page.model.spi.ModelService</role>
<role-hint>event</role-hint>
<field-name>m_eventService</field-name>
<role-hint>transaction</role-hint>
<field-name>m_transactionService</field-name>
</requirement>
</requirements>
</component>
......
......@@ -15,7 +15,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dianping.cat.notify.config.ConfigContext;
import com.dianping.cat.notify.report.AbstractReportCreater;
public class VelocityRender implements IRender {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册