perf[net]: 在task,event,scheduler线程执行的异步请求,请求成功过后依然在相同的线程执行回调任务

This commit is contained in:
godotg
2022-07-28 15:35:44 +08:00
parent 412592110b
commit 004d96a3dd
21 changed files with 202 additions and 230 deletions
@@ -20,6 +20,7 @@ import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.exception.ExceptionUtils;
import com.zfoo.scheduler.manager.SchedulerBus;
import com.zfoo.scheduler.util.TimeUtils;
import com.zfoo.util.SafeRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.support.CronExpression;
@@ -27,7 +28,7 @@ import org.springframework.scheduling.support.CronExpression;
import java.util.concurrent.TimeUnit;
/**
* @author jaysunxiao
* @author godotg
* @version 3.0
*/
public class CronOrmPersister extends AbstractOrmPersister {
@@ -74,13 +75,13 @@ public class CronOrmPersister extends AbstractOrmPersister {
}
if (!OrmContext.isStop()) {
SchedulerBus.schedule(new Runnable() {
SchedulerBus.schedule(new SafeRunnable() {
@Override
public void run() {
public void doRun() {
if (!OrmContext.isStop()) {
EventBus.execute(entityDef.getClazz().hashCode()).execute(new Runnable() {
EventBus.execute(entityDef.getClazz().hashCode(), new SafeRunnable() {
@Override
public void run() {
public void doRun() {
entityCaches.persistAll();
schedulePersist();
}
@@ -19,11 +19,12 @@ import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.util.StringUtils;
import com.zfoo.scheduler.manager.SchedulerBus;
import com.zfoo.util.SafeRunnable;
import java.util.concurrent.TimeUnit;
/**
* @author jaysunxiao
* @author godotg
* @version 3.0
*/
public class TimeOrmPersister extends AbstractOrmPersister {
@@ -43,13 +44,13 @@ public class TimeOrmPersister extends AbstractOrmPersister {
@Override
public void start() {
SchedulerBus.scheduleAtFixedRate(new Runnable() {
SchedulerBus.scheduleAtFixedRate(new SafeRunnable() {
@Override
public void run() {
public void doRun() {
if (!OrmContext.isStop()) {
EventBus.execute(entityDef.getClazz().hashCode()).execute(new Runnable() {
EventBus.execute(entityDef.getClazz().hashCode(), new SafeRunnable() {
@Override
public void run() {
public void doRun() {
entityCaches.persistAll();
}
});
@@ -15,6 +15,7 @@ package com.zfoo.orm.lpmap;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.util.SafeRunnable;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -25,7 +26,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author jaysunxiao
* @author godotg
* @version 3.0
*/
@Ignore
@@ -41,9 +42,9 @@ public class ConcurrentFileChannelMapTest {
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
EventBus.asyncExecute().execute(new Runnable() {
EventBus.asyncExecute(new SafeRunnable() {
@Override
public void run() {
public void doRun() {
var key = atomicInt.getAndIncrement();
while (key < count) {
var myPacket = MyPacket.valueOf(key, String.valueOf(key));
@@ -15,6 +15,7 @@ package com.zfoo.orm.lpmap;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.util.SafeRunnable;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -25,7 +26,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author jaysunxiao
* @author godotg
* @version 3.0
*/
@Ignore
@@ -58,9 +59,9 @@ public class ConcurrentHeapMapTest {
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
EventBus.asyncExecute().execute(new Runnable() {
EventBus.asyncExecute(new SafeRunnable() {
@Override
public void run() {
public void doRun() {
var key = atomicInt.getAndIncrement();
while (key < count) {
var myPacket = MyPacket.valueOf(key, String.valueOf(key));