| | |
| | | @Component |
| | | public class KernelScheduler { |
| | | |
| | | public static int CORE_SCAN_FREQUENCY_MILLISECOND = 30; |
| | | |
| | | private static final int LOCK_TIMEOUT = 5; |
| | | |
| | | private final ReentrantLock lock = new ReentrantLock(Boolean.TRUE); |
| | | |
| | | private Thread trafficCalcThread; |
| | |
| | | this.trafficCalcThread = new Thread(() -> { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | Thread.sleep(100); |
| | | Thread.sleep(CORE_SCAN_FREQUENCY_MILLISECOND); |
| | | |
| | | List<Segment> segments = segmentService.list(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getState, SegmentStateType.WAITING.toString()) |
| | |
| | | for (Segment segment : segments) { |
| | | long startTime = System.currentTimeMillis(); |
| | | trafficService.trigger(segment); |
| | | log.info("traffic calculation spend {} ms", System.currentTimeMillis() - startTime); |
| | | long algoTime = System.currentTimeMillis() - startTime; |
| | | log.info("traffic calculation spend {} ms", algoTime); |
| | | if (segment.getState().equals(SegmentStateType.RUNNING.toString())) { |
| | | segment.setAlgoTime((int) algoTime); |
| | | segmentService.updateById(segment); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | this.actionPublicThread = new Thread(() -> { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | Thread.sleep(100); |
| | | Thread.sleep(CORE_SCAN_FREQUENCY_MILLISECOND); |
| | | |
| | | List<String> actionGroupIds = actionService.selectPrepareGroup(); |
| | | for (String actionGroupId : actionGroupIds) { |
| | | long startTime = System.currentTimeMillis(); |
| | | mainService.publishAction(actionGroupId); |
| | | log.info("publish action calculation spend {} ms", System.currentTimeMillis() - startTime); |
| | | } |
| | | |
| | | } catch (Exception e) { |