Compare commits

...

3 Commits

Author SHA1 Message Date
lijiayao dff5ca8e8d Merge branch 'xiaoyao_correction_code' of https://gitea.qinmian.online/five-groups/work4-16
# Conflicts:
#	src/main/java/com/yao/common/aliy/AliYunEcsService.java
2024-04-19 14:39:45 +08:00
lijiayao 3373a41e44 传入主分支,在分支上修改代码 2024-04-19 14:38:43 +08:00
lijiayao cd903475ce 传入主分支,在分支上修改代码 2024-04-18 21:34:38 +08:00
24 changed files with 351 additions and 206 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
target/
.idea
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

View File

@ -8,6 +8,7 @@ import com.aliyun.teautil.models.RuntimeOptions;
import com.yao.common.aliy.model.EcsSelectModel;
import com.yao.common.config.AlyConfigProperties;
import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.gateway.cache.GatewayNodeSetVinCache;
import com.yao.common.redis.service.RedisService;
import com.yao.gateWay.cache.GatewayAliYunCache;
import lombok.extern.log4j.Log4j2;
@ -26,16 +27,14 @@ import java.util.List;
@Log4j2
public class AliYunEcsService {
@Autowired
private RedisService redisService;
private final AlyConfigProperties alyConfigProperties;
private final Client client;
private final GatewayAliYunCache gatewayAliYunCache;
public AliYunEcsService(AlyConfigProperties alyConfigProperties, Client client, GatewayAliYunCache gatewayAliYunCache) {
private final GatewayNodeSetVinCache gatewayNodeSetVinCache;
public AliYunEcsService(AlyConfigProperties alyConfigProperties, Client client, GatewayNodeSetVinCache gatewayNodeSetVinCache) {
this.alyConfigProperties = alyConfigProperties;
this.client = client;
this.gatewayAliYunCache = gatewayAliYunCache;
this.gatewayNodeSetVinCache = gatewayNodeSetVinCache;
}
//todo----------------------------------------------------以下是查询代码--------------------------------------------
@ -126,7 +125,7 @@ public class AliYunEcsService {
String publicIP = item.getPublicIpAddress().substring(1, item.getPublicIpAddress().length() - 1);
item.setPublicIpAddress(publicIP);
//存入数据
redisService.setCacheSet("new:real:column",item);
gatewayNodeSetVinCache.newInstance(item);
log.info("公网IP:" + item.getPublicIpAddress());
}
);

View File

@ -0,0 +1,28 @@
package com.yao.common.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: LiJiaYao
* @Date: 2024/4/15
* @Description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GateWayNodeInfo {
/**
* id
*/
private String nodeId;
/**
*
*/
private Double score;
}

View File

@ -1,6 +1,7 @@
package com.yao.common.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -12,6 +13,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class WorkGateWayNode {
private String nodeId;

View File

@ -2,12 +2,11 @@ package com.yao.common.mqtt;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yao.common.redis.service.RedisService;
import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import lombok.extern.log4j.Log4j2;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
@ -21,11 +20,11 @@ import java.io.IOException;
@Log4j2
public class MqttConnectService {
/**
* redis
*/
@Autowired
private RedisService redisService;
private GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
public MqttConnectService(GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache) {
this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
}
//todo-----------------------连接mqtt方法-------------------
@ -37,7 +36,7 @@ public class MqttConnectService {
String URL = "http://" + ip + ":8080/public/cluster";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(URL).get().addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").addHeader("Accesstoken", "").build();
redisService.setCacheSet("ECS", ip);
gatewayVehicleLineNodeCache.address(ip);
Response response = null;
try {
response = client.newCall(request).execute();

View File

@ -151,7 +151,6 @@ public class RedisService {
}
/**
* list
*
* @param key
* @return
*/
@ -250,10 +249,30 @@ public class RedisService {
*
* @param key Redis
* @param zValue Hash
* @param value
* @param score
*/
public <T> void setCacheZSet(final String key, final T zValue, final double value) {
redisTemplate.opsForZSet().add(key,zValue,value);
public <T> void setCacheZSet(final String key, final T zValue, final double score) {
redisTemplate.opsForZSet().add(key,zValue,score);
}
/**
*
* @param key
* @return
* @param <T>
*/
public <T> Set<T> getCacheZSet(final String key) {
return redisTemplate.opsForZSet().range(key,0,-1);
}
/**
*
* @param zSetKey
* @return
* @param <T>
*/
public <T> Set<ZSetOperations.TypedTuple<String>> getZSet(String zSetKey) {
return redisTemplate.opsForZSet().rangeWithScores(zSetKey,0,-1);
}
/**
@ -327,4 +346,6 @@ public class RedisService {
return redisTemplate.opsForValue().increment(cursor,l);
}
}

View File

@ -1,19 +0,0 @@
package com.yao.gateWay.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
public class GatewayNodeScoreCache extends GatewayNodeAbstract {
}

View File

@ -1,13 +0,0 @@
package com.yao.gateWay.cache;
import org.springframework.stereotype.Component;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description: vin
*/
@Component
public class GatewayNodeSetVinCache {
}

View File

@ -1,9 +0,0 @@
package com.yao.gateWay.cache;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
public class GatewayVehicleLineNodeCache {
}

View File

@ -1,4 +1,4 @@
package com.yao.gateWay.cache;
package com.yao.gateway.cache;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@ -0,0 +1,58 @@
package com.yao.gateway.cache;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
@Log4j2
public class GatewayArithmeticCache extends GatewayNodeAbstract {
private static final String loadNode ="work:node:gateway";
private static final String cursor ="cursor";
/**
*
*/
public void count(){
redisService.setCacheObject(cursor, 0);
}
/**
*
* @return
*/
public Long increment(){
return redisService.increment(cursor, 1L);
}
/**
* loadNode
*/
public void remove(){
redisService.deleteObject(loadNode);
}
/**
*
* @param loadNodeList
*/
public void loadNode(List<String> loadNodeList){
redisService.setCacheList(loadNode, loadNodeList);
}
/**
* list
* @param count
* @return nodeId
*/
public String cacheList(Long count){
return redisService.getCacheList(loadNode, count % 100);
}
}

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache;
package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache;
package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

View File

@ -1,6 +1,6 @@
package com.yao.gateWay.cache;
package com.yao.gateway.cache;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
/**

View File

@ -0,0 +1,74 @@
package com.yao.gateway.cache;
import com.yao.common.domain.GateWayNodeInfo;
import com.yao.common.domain.WorkGateWayNode;
import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
public class GatewayNodeScoreCache extends GatewayNodeAbstract {
private static final String zSetKey = "gateway:zSet:count";
/**
*
*
* @param info
* @param count
*/
public void newCount(InstanceInfo info, Integer count) {
redisService.setCacheZSet(zSetKey, info, count);
}
/**
*
*
* @return
*/
public Set<InstanceInfo> get() {
Set<InstanceInfo> cacheZSet = redisService.getCacheZSet(zSetKey);
return cacheZSet;
}
/**
*
* @return
*/
public List<GateWayNodeInfo> getCacheZSet() {
Set<ZSetOperations.TypedTuple<String>> set = redisService.getZSet(zSetKey);
// Map<String, Double> nodeMap = set.stream()
// .collect(Collectors.toMap(
// ZSetOperations.TypedTuple::getValue,
// ZSetOperations.TypedTuple::getScore
// ));
return set.stream()
.map(zset->
GateWayNodeInfo.builder()
.nodeId(zset.getValue())
.score(zset.getScore())
.build()
).toList();
//算法:有没有超过百分比
// double sum = nodeMap.values().stream().mapToDouble(value -> value).sum();
}
/**
*
*/
public void remove() {
redisService.deleteObject(zSetKey);
}
}

View File

@ -1,20 +1,19 @@
package com.yao.gateWay.cache;
package com.yao.gateway.cache;
import com.aliyun.teautil.Common;
import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
* @Description: vin
*/
@Component
public class GatewayAliYunCache extends GatewayNodeAbstract {
public class GatewayNodeSetVinCache extends GatewayNodeAbstract {
/**
*
*/
@ -33,8 +32,16 @@ public class GatewayAliYunCache extends GatewayNodeAbstract {
* @param realKey
* @return
*/
public Set<InstanceInfo> get(String realKey){
public Set<InstanceInfo> get(){
return redisService.getCacheSet(realKey);
}
/**
* key
* @param realKey new:real:column
* @param info
*/
public void remote(InstanceInfo info){
redisService.deleteCacheMapValue(realKey, Common.toJSONString(info));
}
}

View File

@ -0,0 +1,44 @@
package com.yao.gateway.cache;
import com.yao.gateway.cache.abs.GatewayNodeAbstract;
import org.springframework.stereotype.Component;
import java.util.Set;
/**
* @Author: LiJiaYao
* @Date: 2024/4/18
* @Description:
*/
@Component
public class GatewayVehicleLineNodeCache extends GatewayNodeAbstract {
private final static String reconnectCar = "reconnectCar";
/**
*
* @param ip ip
*/
public void save(String ip){
redisService.setCacheSet(reconnectCar,ip);
}
/**
* ip
* @param ip ip
*/
public void address(String ip) {
redisService.setCacheSet("ECS", ip);
}
/**
* ecsip
*/
public Set<String> getAddress() {
return redisService.getCacheSet("ECS");
}
}

View File

@ -1,4 +1,4 @@
package com.yao.gateWay.cache.abs;
package com.yao.gateway.cache.abs;
import com.yao.common.redis.service.RedisService;
@ -14,8 +14,4 @@ public abstract class GatewayNodeAbstract {
*/
public RedisService redisService;
}

View File

@ -18,7 +18,6 @@ public class LoadController {
private LoadService loadService;
@PostMapping("/load")
public Result<?> loadInfo(){
String load = loadService.load();
return Result.success(load);
return Result.success(loadService.load());
}
}

View File

@ -1,9 +1,9 @@
package com.yao.server.service.impl;
import com.yao.gateWay.cache.GateWayNodeInfo;
import com.yao.gateWay.cache.GatewayLoadNodeCache;
import com.yao.gateWay.cache.GatewayLoadSeriesCache;
import com.yao.gateWay.cache.GatewayNodeCache;
import com.yao.gateway.cache.GateWayNodeInfo;
import com.yao.gateway.cache.GatewayLoadNodeCache;
import com.yao.gateway.cache.GatewayLoadSeriesCache;
import com.yao.gateway.cache.GatewayNodeCache;
import com.yao.server.service.GatewayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

View File

@ -3,10 +3,10 @@ package com.yao.server.service.impl;
import com.yao.common.config.Constants;
import com.yao.common.domain.WorkGateWayNode;
import com.yao.common.mqtt.MqttConnectService;
import com.yao.common.redis.service.RedisService;
import com.yao.gateway.cache.GatewayArithmeticCache;
import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import com.yao.server.service.LoadService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@ -21,20 +21,22 @@ import java.util.concurrent.CountDownLatch;
@Log4j2
@Service
public class LoadServiceImpl implements LoadService {
@Autowired
private RedisService redisService;
//网关算法缓存
private final GatewayArithmeticCache gatewayArithmeticCache;
// 网关连接车俩
private final GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
private MqttConnectService mqttConnectService;
public LoadServiceImpl(MqttConnectService mqttConnectService) {
public LoadServiceImpl(GatewayArithmeticCache gatewayArithmeticCache, GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache, MqttConnectService mqttConnectService) {
this.gatewayArithmeticCache = gatewayArithmeticCache;
this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
this.mqttConnectService = mqttConnectService;
}
@Override
public String load() {
//初始化序列
redisService.setCacheObject("cursor", 0);
gatewayArithmeticCache.count();
ArrayList<WorkGateWayNode> nodeIdList = carWorkGatewayNode();
//100
List<String> loadNodeList = new ArrayList<>();
@ -68,13 +70,13 @@ public class LoadServiceImpl implements LoadService {
}
}
}
redisService.deleteObject("work:node:gateway");
redisService.setCacheList("work:node:gateway", loadNodeList);
gatewayArithmeticCache.remove();
gatewayArithmeticCache.loadNode(loadNodeList);
CountDownLatch countDownLatch = new CountDownLatch(300);
new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) {
long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
long cursor = gatewayArithmeticCache.increment();
String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList);
countDownLatch.countDown();
@ -83,8 +85,8 @@ public class LoadServiceImpl implements LoadService {
new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) {
long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
long cursor = gatewayArithmeticCache.increment();
String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList);
countDownLatch.countDown();
@ -93,8 +95,8 @@ public class LoadServiceImpl implements LoadService {
new Thread(() -> {
for (int i = 0; i < Constants.SUM; i++) {
Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
long cursor = gatewayArithmeticCache.increment();
String cacheList = gatewayArithmeticCache.cacheList(cursor);
log.info(cursor + "---------" + cacheList);
SitNode.sti(cacheList);
countDownLatch.countDown();
@ -123,7 +125,7 @@ public class LoadServiceImpl implements LoadService {
}
public ArrayList<WorkGateWayNode> carWorkGatewayNode() {
Set<String> ip = redisService.getCacheSet("ECS");
Set<String> ip = gatewayVehicleLineNodeCache.getAddress();
ArrayList<WorkGateWayNode> list = new ArrayList<>();
for (String s : ip) {
Integer connectSize = mqttConnectService.connectMqtt(s);
@ -170,6 +172,4 @@ class SitNode {
return map;
}
}

View File

@ -1,11 +1,9 @@
package com.yao.server.test;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.DescribeAvailableResourceRequest;
import com.aliyun.ecs20140526.models.DescribeAvailableResourceResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;
/**
* @Author: LiJiaYao

View File

@ -1,20 +1,18 @@
package com.yao.server.timer;
import com.aliyun.teautil.Common;
import com.yao.common.aliy.AliYunEcsService;
import com.yao.common.aliy.model.EcsSelectModel;
import com.yao.common.domain.GateWayNodeInfo;
import com.yao.common.domain.aliy.InstanceInfo;
import com.yao.common.domain.aliy.InstanceRequest;
import com.yao.common.mqtt.MqttConnectService;
import com.yao.common.redis.service.RedisService;
import com.yao.gateway.cache.GatewayNodeScoreCache;
import com.yao.gateway.cache.GatewayNodeSetVinCache;
import com.yao.gateway.cache.GatewayVehicleLineNodeCache;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -27,96 +25,61 @@ import java.util.Set;
@EnableAsync //开启异步支持
@Component
public class Timer {
private final AliYunEcsService aliYunEcsService;
private final MqttConnectService mqttConnectService;
// 阿里云缓存
private final GatewayNodeSetVinCache gatewayNodeSetVinCache;
private final GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache;
private final GatewayNodeScoreCache gatewayNodeScoreCache;
@Autowired
private RedisService redisService;
private AliYunEcsService aliYunEcsService;
private MqttConnectService mqttConnectService;
public Timer(AliYunEcsService aliYunEcsService, MqttConnectService mqttConnectService) {
public Timer(AliYunEcsService aliYunEcsService, MqttConnectService mqttConnectService, GatewayNodeSetVinCache gatewayAliYunCache, GatewayVehicleLineNodeCache gatewayVehicleLineNodeCache, GatewayNodeScoreCache gatewayNodeScoreCache) {
this.aliYunEcsService = aliYunEcsService;
this.mqttConnectService = mqttConnectService;
this.gatewayNodeSetVinCache = gatewayAliYunCache;
this.gatewayVehicleLineNodeCache = gatewayVehicleLineNodeCache;
this.gatewayNodeScoreCache = gatewayNodeScoreCache;
}
@Async
@Scheduled(cron = "0/20 * * * * ?")
public void timer() {
long startTime = System.currentTimeMillis(); // 记录开始时间
long endTime = startTime + 10 * 60 * 1000; // 设置结束时间为10分钟后
// redisService.deleteObject("new:real:column");
Set<InstanceInfo> instance = redisService.getCacheSet("new:real:column");
// List<InstanceInfo> myFirstEcsInstance = null;
// try {
// myFirstEcsInstance = aliYunEcsService.selectList(ecsSelectModelName("MyFirstEcsInstance"));
// for (InstanceInfo instanceInfo : myFirstEcsInstance) {
// String publicIpAddress = instanceInfo.getPublicIpAddress();
// String instanceId = instanceInfo.getInstanceId();
// InstanceRequest instanceRequest = new InstanceRequest(publicIpAddress, instanceId);
// redisService.setCacheSet("new:real:column", instanceRequest);
// }
if (instance.isEmpty()) {
// if (myFirstEcsInstance.isEmpty()) {
// 记录开始时间
long startTime = System.currentTimeMillis();
// 设置结束时间为10分钟后
long endTime = startTime + 10 * 60 * 1000;
Set<InstanceInfo> instance = gatewayNodeSetVinCache.get();
if (instance.isEmpty()) {
try {
aliYunEcsService.startCreate();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
for (InstanceInfo s : instance) {
Integer connectSize = mqttConnectService.connectMqtt(s.getPublicIpAddress());
List<String> instanceId = null;
String deleteInstanceId = null;
if (connectSize >= 79) {
//执行节点扩容
//返回实例的ID
if (!instanceId.isEmpty()) {
try {
aliYunEcsService.startCreate();
instanceId = aliYunEcsService.startCreate();
log.info("扩容成功!");
log.info("扩容的节点id为" + instanceId);
} catch (Exception e) {
throw new RuntimeException(e);
}
// }
}
for (InstanceInfo s : instance) {
Integer connectSize = mqttConnectService.connectMqtt(s.getPublicIpAddress());
List<String> instanceId = null;
String deleteInstanceId = null;
if (connectSize >= 80) {
//执行节点扩容
//返回实例的ID
if (!instanceId.isEmpty()) {
try {
instanceId = aliYunEcsService.startCreate();
log.info("扩容成功!");
log.info("扩容的节点id为" + instanceId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
if (connectSize <= 20 && System.currentTimeMillis() < endTime) {
// if (!deleteInstanceId.isEmpty()) {
aliYunEcsService.delete(s.getInstanceId());
//删除实列以后再去把redis的值删除 再去通知重新上线
redisService.deleteCacheMapValue("new:real:column", Common.toJSONString(s));
redisService.setCacheSet("reconnectCar",s.getPublicIpAddress());
log.info("缩容成功!");
log.info("锁容的节点id为" + deleteInstanceId);
}
}
// } catch (Exception e) {
// throw new RuntimeException(e);
if (connectSize <= 20 && System.currentTimeMillis() < endTime) {
aliYunEcsService.delete(s.getInstanceId());
//删除实列以后再去把redis的值删除 再去通知重新上线
gatewayNodeSetVinCache.remote(s);
gatewayVehicleLineNodeCache.save(s.getPublicIpAddress());
log.info("缩容成功!");
log.info("锁容的节点id为" + deleteInstanceId);
}
}
}
/**
*
*
* @param instance
* @return
*/
// public EcsSelectModel ecsSelectModel(Set<InstanceInfo> instance) {
// List<String> instanceIdList = new ArrayList<>();
// for (InstanceInfo req : instance) {
// instanceIdList.add(req.getInstanceId());
// }
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
// ecsSelectModel.setInstanceIdList(instanceIdList);
// return ecsSelectModel;
// }
// public EcsSelectModel ecsSelectModelName(String instanceName) {
// List<String> instanceIdList = new ArrayList<>();
// instanceIdList.add(instanceName);
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
// ecsSelectModel.setInstanceIdList(instanceIdList);
// return ecsSelectModel;
// }
//}
}

View File

@ -20,13 +20,10 @@ import java.util.concurrent.CountDownLatch;
@SpringBootTest(classes = APISpringBootApplication.class)
public class LoadService1 {
@Autowired
private RedisService redisService;
@Test
public void load() {
//初始化序列
redisService.setCacheObject("cursor",0);
// redisService.setCacheObject("cursor",0);
List<WorkGateWayNode> nodeIdList = new ArrayList() {
{
@ -77,33 +74,33 @@ public class LoadService1 {
// for (int i = 0; i < 100; i++) {
// loadNodeList.add(nodeIdList.get(i % nodeIdList.size()));
// }
redisService.deleteObject("work:node:gateway");
redisService.setCacheList("work:node:gateway",loadNodeList);
// redisService.deleteObject("work:node:gateway");
// redisService.setCacheList("work:node:gateway",loadNodeList);
CountDownLatch countDownLatch = new CountDownLatch(300);
new Thread(()->{
for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList);
// Long cursor = redisService.increment("cursor", 1L);
// String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
// log.info(cursor+"---------"+cacheList);
// SitNode.sti(cacheList);
countDownLatch.countDown();
}
}).start();
new Thread(()->{
for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList);
// Long cursor = redisService.increment("cursor", 1L);
// String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
// log.info(cursor+"---------"+cacheList);
// SitNode.sti(cacheList);
countDownLatch.countDown();
}
}).start();
new Thread(()->{
for (int i = 0; i < 100; i++) {
Long cursor = redisService.increment("cursor", 1L);
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
log.info(cursor+"---------"+cacheList);
SitNode.sti(cacheList);
// Long cursor = redisService.increment("cursor", 1L);
// String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
// log.info(cursor+"---------"+cacheList);
// SitNode.sti(cacheList);
countDownLatch.countDown();
}
}).start();