feat: add max queue size for log handler in worker to prevent OOM

This commit is contained in:
tjq 2022-09-18 14:02:05 +08:00
parent 483227f840
commit f3c7ed8baf

View File

@ -35,7 +35,7 @@ public class OmsLogHandler {
// 上报锁只需要一个线程上报即可 // 上报锁只需要一个线程上报即可
private final Lock reportLock = new ReentrantLock(); private final Lock reportLock = new ReentrantLock();
// 生产者消费者模式异步上传日志 // 生产者消费者模式异步上传日志
private final BlockingQueue<InstanceLogContent> logQueue = Queues.newLinkedBlockingQueue(); private final BlockingQueue<InstanceLogContent> logQueue = Queues.newLinkedBlockingQueue(10240);
// 每次上报携带的数据条数 // 每次上报携带的数据条数
private static final int BATCH_SIZE = 20; private static final int BATCH_SIZE = 20;
@ -61,7 +61,10 @@ public class OmsLogHandler {
} }
InstanceLogContent tuple = new InstanceLogContent(instanceId, System.currentTimeMillis(), logLevel.getV(), logContent); InstanceLogContent tuple = new InstanceLogContent(instanceId, System.currentTimeMillis(), logLevel.getV(), logContent);
logQueue.offer(tuple); boolean offerRet = logQueue.offer(tuple);
if (!offerRet) {
log.warn("[OmsLogHandler] [{}] submit log failed, maybe your log speed is too fast!", instanceId);
}
} }