mirror of
https://github.com/luoyan35714/OPC_Client.git
synced 2026-04-18 00:01:30 +08:00
refactor the async perf test and change the encode
This commit is contained in:
+11
-23
@@ -7,54 +7,42 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.SyncAccess;
|
||||
|
||||
import com.freud.opc.utgard.perf.common.DataCallBackListener;
|
||||
|
||||
public class AsyncOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(AsyncOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
private static final int NUMBER = 10;
|
||||
private static final int count = 1;
|
||||
public static long start;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int i = 1; i <= WAN_NUMBER; i++) {
|
||||
testSteps(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testSteps(int count) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
LOGGER.info("Step-" + count + "W:");
|
||||
LOGGER.info("StartDate[" + new Date() + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
Executors.newScheduledThreadPool(4));
|
||||
|
||||
server.connect();
|
||||
|
||||
AccessBase access = new SyncAccess(server, 1000);
|
||||
int limit = count * NUMBER;
|
||||
for (int i = 0; i < limit; i++) {
|
||||
access.addItem("Random.Real" + i, new DataCallback() {
|
||||
@Override
|
||||
public void changed(Item item, ItemState is) {
|
||||
LOGGER.info("Item:[" + item.getId() + "], Value:["
|
||||
+ is.getValue() + "]");
|
||||
}
|
||||
});
|
||||
access.addItem("Random.Real" + i, new DataCallBackListener(limit));
|
||||
}
|
||||
|
||||
access.bind();
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(5000);
|
||||
access.unbind();
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("EndDate[" + new Date() + "],CurrentMillis:" + end);
|
||||
LOGGER.info("Total Spend:[" + (end - start) + "]");
|
||||
|
||||
server.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class PublishOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(PublishOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int NUMBER = 10;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
+4
-5
@@ -4,7 +4,6 @@ import static com.freud.opc.utgard.perf.config.ConfigReader.config;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
@@ -15,8 +14,8 @@ public class SyncOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(SyncOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
private static final int NUMBER = 100;
|
||||
private static final int WAN_NUMBER = 1;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int i = 1; i <= WAN_NUMBER; i++) {
|
||||
@@ -30,8 +29,7 @@ public class SyncOPCPerfTest {
|
||||
LOGGER.info("Step-" + count + "W:");
|
||||
LOGGER.info("startDate[" + new Date() + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
Server server = new Server(config(), null);
|
||||
|
||||
server.connect();
|
||||
|
||||
@@ -57,6 +55,7 @@ public class SyncOPCPerfTest {
|
||||
LOGGER.info("Start Read[" + new Date() + "],CurrentMillis:" + read);
|
||||
|
||||
group.read(true, items);
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("End Read[" + new Date() + "],CurrentMillis:" + end);
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.freud.opc.utgard.perf.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
|
||||
import com.freud.opc.utgard.perf.AsyncOPCPerfTest;
|
||||
|
||||
public class DataCallBackListener implements DataCallback {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(DataCallBackListener.class);
|
||||
|
||||
private static List<String> items = new ArrayList<String>();
|
||||
|
||||
private int size;
|
||||
|
||||
public DataCallBackListener(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changed(Item item, ItemState is) {
|
||||
LOGGER.info("Item:[" + item.getId() + "], Value:[" + is.getValue()
|
||||
+ "]");
|
||||
items.add(item.getId());
|
||||
if (items.size() == size) {
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("EndDate[" + new Date() + "],CurrentMillis:" + end);
|
||||
LOGGER.info("Total Spend:[" + (end - AsyncOPCPerfTest.start) + "]");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
-7
@@ -1,12 +1,5 @@
|
||||
package com.freud.opc.utgard.perf.config;
|
||||
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.CLSID;
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.DOMAIN;
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.HOST;
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.PASSWORD;
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.USERNAME;
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.getProp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user