mirror of
https://github.com/luoyan35714/OPC_Client.git
synced 2026-04-18 00:01:30 +08:00
Add the utgard performance test
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
package com.freud.opc.utgard.perf;
|
||||
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.config;
|
||||
|
||||
import java.util.Date;
|
||||
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;
|
||||
|
||||
public class AsyncOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(AsyncOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
|
||||
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();
|
||||
|
||||
LOGGER.info("Step-" + count + "W:");
|
||||
LOGGER.info("StartDate[" + new Date() + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
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.bind();
|
||||
Thread.sleep(1000);
|
||||
access.unbind();
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("EndDate[" + new Date() + "],CurrentMillis:" + end);
|
||||
LOGGER.info("Total Spend:[" + (end - start) + "]");
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.freud.opc.utgard.perf;
|
||||
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.config;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.Async20Access;
|
||||
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;
|
||||
|
||||
public class PublishOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(PublishOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
|
||||
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();
|
||||
|
||||
LOGGER.info("Step-" + count + "W:");
|
||||
LOGGER.info("StartDate[" + new Date() + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
AccessBase access = new Async20Access(server, 1000, true);
|
||||
|
||||
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.bind();
|
||||
Thread.sleep(1000);
|
||||
access.unbind();
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("EndDate[" + new Date() + "],CurrentMillis:" + end);
|
||||
LOGGER.info("Total Spend:[" + (end - start) + "]");
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.freud.opc.utgard.perf;
|
||||
|
||||
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;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
public class SyncOPCPerfTest {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(SyncOPCPerfTest.class);
|
||||
|
||||
private static final int NUMBER = 10000;
|
||||
private static final int WAN_NUMBER = 10;
|
||||
|
||||
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();
|
||||
|
||||
LOGGER.info("Step-" + count + "W:");
|
||||
LOGGER.info("startDate[" + new Date() + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
|
||||
server.connect();
|
||||
|
||||
Group group = server.addGroup();
|
||||
|
||||
int limit = count * NUMBER;
|
||||
Item[] items = new Item[limit];
|
||||
|
||||
long createStart = System.currentTimeMillis();
|
||||
LOGGER.info("Create the items[" + new Date() + "],CurrentMillis:"
|
||||
+ createStart);
|
||||
|
||||
for (int i = 0; i < limit; i++) {
|
||||
Item item = group.addItem("Random.Real" + i);
|
||||
items[i] = item;
|
||||
}
|
||||
|
||||
long createEnd = System.currentTimeMillis();
|
||||
LOGGER.info("Create finish [" + new Date() + "],CurrentMillis:"
|
||||
+ createEnd);
|
||||
|
||||
long read = System.currentTimeMillis();
|
||||
LOGGER.info("Start Read[" + new Date() + "],CurrentMillis:" + read);
|
||||
|
||||
group.read(true, items);
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info("End Read[" + new Date() + "],CurrentMillis:" + end);
|
||||
|
||||
LOGGER.info(MessageFormat.format(
|
||||
"Total[{0}], CreateItem[{1}], Read[{2}]", end - start,
|
||||
createEnd - createStart, end - read));
|
||||
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
|
||||
public class ConfigReader {
|
||||
|
||||
private static Properties prop;
|
||||
|
||||
public static final String HOST = "host";
|
||||
public static final String DOMAIN = "domain";
|
||||
public static final String USERNAME = "username";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String CLSID = "clsid";
|
||||
public static final String PROGID = "progid";
|
||||
|
||||
static {
|
||||
try {
|
||||
prop = new Properties();
|
||||
prop.load(ConfigReader.class.getClassLoader().getResourceAsStream(
|
||||
"config.properties"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProp(String name) {
|
||||
return prop.getProperty(name);
|
||||
}
|
||||
|
||||
public static ConnectionInformation config() {
|
||||
ConnectionInformation ci = new ConnectionInformation();
|
||||
ci.setHost(getProp(HOST));
|
||||
ci.setDomain(getProp(DOMAIN));
|
||||
ci.setUser(getProp(USERNAME));
|
||||
ci.setPassword(getProp(PASSWORD));
|
||||
ci.setClsid(getProp(CLSID));
|
||||
return ci;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
log4j.rootCategory=INFO,stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n
|
||||
|
||||
log4j.appender.utgard=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.utgard.File=utgard_result.log
|
||||
log4j.appender.utgard.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.utgard.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n
|
||||
|
||||
log4j.logger.com.freud.opc.utgard.perf=DEBUG,utgard
|
||||
Reference in New Issue
Block a user