mirror of
https://github.com/luoyan35714/OPC_Client.git
synced 2026-04-18 00:01:30 +08:00
Add the sync test cases
This commit is contained in:
+16
-15
@@ -2,8 +2,6 @@ package com.freud.opc.utgard.perf;
|
||||
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
@@ -19,15 +17,17 @@ public class SyncMultiThreadTest {
|
||||
|
||||
public synchronized static void end(long in) {
|
||||
end = in;
|
||||
LOGGER.info("Asynch read total used[" + (end - start) + "] s");
|
||||
LOGGER.info("[" + (count * TestMultiple.NUMBER)
|
||||
+ "] Asynch read total used[" + (end - start) + "] s");
|
||||
}
|
||||
|
||||
private static long start;
|
||||
private static long end;
|
||||
|
||||
private static final int count = 100;
|
||||
private static final int count = 6;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
LOGGER.info("----------------------");
|
||||
for (int i = 1; i <= count; i++) {
|
||||
new Thread(new TestMultiple(i)).start();
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class TestMultiple implements Runnable {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(TestMultiple.class);
|
||||
|
||||
private static final int NUMBER = 4000;
|
||||
public static final int NUMBER = 25000;
|
||||
|
||||
private int count_number;
|
||||
|
||||
@@ -60,21 +60,21 @@ class TestMultiple implements Runnable {
|
||||
|
||||
int limit = count_number * NUMBER;
|
||||
|
||||
LOGGER.info("[" + limit + ":]" + "Step-" + limit + ":");
|
||||
LOGGER.info("[" + limit + ":]" + "startDate[" + new Date()
|
||||
+ "],CurrentMillis:" + start);
|
||||
// LOGGER.info("[" + limit + ":]" + "Step-" + limit + ":");
|
||||
// LOGGER.info("[" + limit + ":]" + "startDate[" + new Date()
|
||||
// + "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(), null);
|
||||
|
||||
server.connect();
|
||||
|
||||
Group group = server.addGroup();
|
||||
Group group = server.addGroup(count_number + "");
|
||||
|
||||
Item[] items = new Item[NUMBER];
|
||||
|
||||
long createStart = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Create the items[" + new Date()
|
||||
+ "],CurrentMillis:" + createStart);
|
||||
// LOGGER.info("[" + limit + "W:]" + "Create the items[" + new Date()
|
||||
// + "],CurrentMillis:" + createStart);
|
||||
|
||||
for (int i = (count_number - 1) * NUMBER; i < limit; i++) {
|
||||
Item item = group.addItem("Random.Real" + i);
|
||||
@@ -82,12 +82,12 @@ class TestMultiple implements Runnable {
|
||||
}
|
||||
|
||||
long createEnd = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Create finish [" + new Date()
|
||||
+ "],CurrentMillis:" + createEnd);
|
||||
// LOGGER.info("[" + limit + "W:]" + "Create finish [" + new Date()
|
||||
// + "],CurrentMillis:" + createEnd);
|
||||
|
||||
long read = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Start Read[" + new Date()
|
||||
+ "],CurrentMillis:" + read);
|
||||
// LOGGER.info("[" + limit + "W:]" + "Start Read[" + new Date()
|
||||
// + "],CurrentMillis:" + read);
|
||||
SyncMultiThreadTest.start(read);
|
||||
group.read(true, items);
|
||||
|
||||
@@ -99,6 +99,7 @@ class TestMultiple implements Runnable {
|
||||
// + "Total[{0}], CreateItem[{1}], Read[{2}]", end - start,
|
||||
// createEnd - createStart, end - read));
|
||||
|
||||
group.clear();
|
||||
group.remove();
|
||||
server.dispose();
|
||||
}
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.freud.opc.utgard.perf;
|
||||
|
||||
import static com.freud.opc.utgard.perf.config.ConfigReader.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
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 SyncMultiThreadTest2 {
|
||||
private static Logger LOGGER = Logger.getLogger(SyncMultiThreadTest2.class);
|
||||
|
||||
private static long[] start = new long[10];
|
||||
private static long[] end = new long[10];
|
||||
|
||||
public synchronized static void start(int time, long in) {
|
||||
if (start[time] == 0)
|
||||
start[time] = in;
|
||||
}
|
||||
|
||||
public synchronized static void end(int time, long in) {
|
||||
end[time] = in;
|
||||
LOGGER.info(time + "-Asynch read total used["
|
||||
+ (end[time] - start[time]) + "] s");
|
||||
}
|
||||
|
||||
private static final int count = 1;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int time = 1; time <= 10; time++) {
|
||||
for (int i = 1; i <= count; i++) {
|
||||
new Thread(new TestMultiple2(time, i)).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestMultiple2 implements Runnable {
|
||||
|
||||
private static Logger LOGGER = Logger.getLogger(TestMultiple2.class);
|
||||
|
||||
private static final int NUMBER = 2 * 10000;
|
||||
private int time;
|
||||
private int count_number;
|
||||
|
||||
public TestMultiple2(int time, int count_number) {
|
||||
this.time = time;
|
||||
this.count_number = count_number;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
testSteps();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void testSteps() throws Exception {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
int limit = count_number * NUMBER;
|
||||
|
||||
LOGGER.info("[" + limit + ":]" + "Step-" + limit + ":");
|
||||
LOGGER.info("[" + limit + ":]" + "startDate[" + new Date()
|
||||
+ "],CurrentMillis:" + start);
|
||||
|
||||
Server server = new Server(config(), null);
|
||||
|
||||
server.connect();
|
||||
|
||||
Group group = server.addGroup();
|
||||
|
||||
Item[] items = new Item[NUMBER];
|
||||
|
||||
long createStart = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Create the items[" + new Date()
|
||||
+ "],CurrentMillis:" + createStart);
|
||||
|
||||
for (int i = (count_number - 1) * NUMBER; i < limit; i++) {
|
||||
Item item = group.addItem("Random.Real" + i);
|
||||
items[i % NUMBER] = item;
|
||||
}
|
||||
|
||||
long createEnd = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Create finish [" + new Date()
|
||||
+ "],CurrentMillis:" + createEnd);
|
||||
|
||||
long read = System.currentTimeMillis();
|
||||
LOGGER.info("[" + limit + "W:]" + "Start Read[" + new Date()
|
||||
+ "],CurrentMillis:" + read);
|
||||
SyncMultiThreadTest2.start(time, read);
|
||||
group.read(true, items);
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
// LOGGER.info("[" + limit + "W:]" + "End Read[" + new Date()
|
||||
// + "],CurrentMillis:" + end);
|
||||
SyncMultiThreadTest2.end(time, end);
|
||||
// LOGGER.info(MessageFormat.format("[" + limit + "W:]"
|
||||
// + "Total[{0}], CreateItem[{1}], Read[{2}]", end - start,
|
||||
// createEnd - createStart, end - read));
|
||||
|
||||
group.remove();
|
||||
server.dispose();
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.freud.opc.utgard.perf.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class CountAverageNumber {
|
||||
|
||||
private static int i = 5;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
|
||||
StringBuilder fileName = new StringBuilder("result/result_count_" + i
|
||||
+ ".txt");
|
||||
InputStream is = new FileInputStream(new File(fileName.toString()));
|
||||
Reader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
|
||||
String line = null;
|
||||
|
||||
int index = 0;
|
||||
int tmp = 0;
|
||||
List<Integer> list = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.contains("W-")) {
|
||||
tmp = Integer.valueOf(line.split("-")[0].replace("W", "")
|
||||
.replace("w", ""));
|
||||
if (tmp != index) {
|
||||
if (list != null) {
|
||||
map.put(index, list);
|
||||
}
|
||||
index = tmp;
|
||||
list = new ArrayList<Integer>();
|
||||
|
||||
}
|
||||
} else {
|
||||
if (line != null && !line.isEmpty())
|
||||
list.add(Integer.valueOf(line.trim().split(
|
||||
"Asynch read total used")[1].replace("] s", "")
|
||||
.replace("[", "")));
|
||||
}
|
||||
}
|
||||
map.put(index, list);
|
||||
|
||||
for (Entry<Integer, List<Integer>> entry : map.entrySet()) {
|
||||
if (entry.getValue().size() > 0) {
|
||||
int total = 0;
|
||||
for (int item : entry.getValue()) {
|
||||
total += item;
|
||||
}
|
||||
System.out.println(entry.getKey() + "w-average["
|
||||
+ (total / entry.getValue().size()) + "ms]");
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
|
||||
if (isr != null) {
|
||||
isr.close();
|
||||
}
|
||||
if (br != null) {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.freud.opc.utgard.perf.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
public class FileWriterUtil {
|
||||
|
||||
private static File file;
|
||||
|
||||
private static FileOutputStream fos;
|
||||
private static BufferedWriter bw;
|
||||
|
||||
public static void init(String fileName) throws FileNotFoundException {
|
||||
file = new File(fileName);
|
||||
fos = new FileOutputStream(file, true);
|
||||
bw = new BufferedWriter(new OutputStreamWriter(fos));
|
||||
}
|
||||
|
||||
public static void write(String content) throws IOException {
|
||||
bw.write(content + "\r\n");
|
||||
}
|
||||
|
||||
public static void finish() throws IOException {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
|
||||
if (bw != null) {
|
||||
bw.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user