Browse Source

IOT调用测试

master
林万龙 3 years ago
parent
commit
caab226eac
1 changed files with 19 additions and 2 deletions
  1. +19
    -2
      src/main/java/com/telpo/iotgateway/server/IotCommunication.java

+ 19
- 2
src/main/java/com/telpo/iotgateway/server/IotCommunication.java View File

@@ -70,6 +70,10 @@ public class IotCommunication {


String ProductKey = "a18mXM6Cvx8"; String ProductKey = "a18mXM6Cvx8";
String DeviceName = "800115470000678"; String DeviceName = "800115470000678";
long reqCount = 0;
long reqLongCount = 0;
long allOfManTime = 0;
long appStartTime = (new DateTime()).getTime();


DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret); DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
IAcsClient client = new DefaultAcsClient(profile); IAcsClient client = new DefaultAcsClient(profile);
@@ -100,15 +104,28 @@ public class IotCommunication {
request.putQueryParameter("DeviceName", DeviceName); request.putQueryParameter("DeviceName", DeviceName);


long startTime = (new DateTime()).getTime(); long startTime = (new DateTime()).getTime();
log.debug("开始IOT请求");
//log.debug("开始IOT请求");
CommonResponse response = client.getCommonResponse(request); CommonResponse response = client.getCommonResponse(request);
long endTime = (new DateTime()).getTime(); long endTime = (new DateTime()).getTime();
long useTime = endTime-startTime; long useTime = endTime-startTime;
log.debug("结束IOT请求, 用时:" + useTime);
allOfManTime = allOfManTime + useTime;
//log.debug("结束IOT请求, 用时:" + useTime);
Thread.sleep(10); Thread.sleep(10);
if (useTime > 2000) { if (useTime > 2000) {
reqLongCount++;
log.debug(response.getData()); log.debug(response.getData());
} }
reqCount++;
if (reqCount == 10000) {
long appPassTime = (new DateTime()).getTime();
log.info("10000请求用时秒数:" + (appPassTime-appStartTime)/1000);
log.info("用时超过2秒次数:" + reqLongCount);
log.info("平均每次请求用时(毫秒):" + allOfManTime/10000);
reqCount = 0;
allOfManTime = 0;
appStartTime = appPassTime;
reqLongCount=0;
}
} }
} catch (ServerException e) { } catch (ServerException e) {
log.error("IllegalArgumentException:{}", e.getMessage()); log.error("IllegalArgumentException:{}", e.getMessage());


Loading…
Cancel
Save