-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHTTest.java
More file actions
119 lines (105 loc) · 3.31 KB
/
HTTest.java
File metadata and controls
119 lines (105 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.concurrent.*;
import java.util.zip.GZIPOutputStream;
public class HTTest {
static int ThreadNum = 1;
static int Duration = 300;
static int ArraySize = 102;
static int CountDownSize = 1000 * 1000 * 30;
static int reportInterval = 2;
public static void main(String[] args) throws IOException {
if (args.length > 0) {
ThreadNum = Integer.parseInt(args[0]);
Duration = Integer.parseInt(args[1]);
}
for (int i = 0; i < ThreadNum; i++) {
String filename = Integer.toString(i) + ".log";
LoadThread thread = new LoadThread(i, filename);
thread.start();
}
}
}
class LoadThread extends Thread {
long timeZero = 0;
long finishedUnit = 0;
long threadid;
PrintWriter file_th;
PrintWriter file_finish;
PrintWriter file_latency;
public LoadThread(int id, String Filename) {
timeZero = System.currentTimeMillis();
}
public void run() {
try {
threadid = Thread.currentThread().getId();
file_th = new PrintWriter("throughput." + Long.toString(threadid)
+ ".csv", "UTF-8");
file_finish = new PrintWriter("finish." + Long.toString(threadid)
+ ".csv", "UTF-8");
file_latency = new PrintWriter("latency." + Long.toString(threadid)
+ ".csv", "UTF-8");
} catch (Exception e) {
}
AbstractQueue<String> q = new ArrayBlockingQueue<String>(
HTTest.CountDownSize * 2);
char[] srcArray = new char[HTTest.ArraySize];
String emptystr = new String(srcArray);
finishedUnit = 0;
long prevTime = timeZero;
long prevFinished = 0;
boolean stopRun = false;
long reportUnit = 1000 * 1000 * 1;
while (!stopRun) {
if (q.size() >= HTTest.CountDownSize) {
String strHuge_remove = null;
for (int j = 0; j < HTTest.CountDownSize / 10; j++) {
strHuge_remove = q.remove();
}
}
if (q.size() % 100 == 0) {
long curTime = System.currentTimeMillis();
long timeDiff = curTime - prevTime;
if (timeDiff > HTTest.reportInterval * 1000) {
prevTime = curTime;
long totalTime = curTime - timeZero;
long deltaFinished = finishedUnit - prevFinished;
prevFinished = finishedUnit;
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSSSS");
System.out.println(ft.format(dNow) + " thread_id="
+ threadid + " last throughput (unit/second)="
+ deltaFinished / reportUnit / (timeDiff / 1000.0));
System.out.println(ft.format(dNow) + " thread_id="
+ threadid + " finished Units =" + finishedUnit
/ reportUnit);
file_th.println(ft.format(dNow) + "," + deltaFinished
/ reportUnit / (timeDiff / 1000.0));
file_finish.println(ft.format(dNow) + "," + finishedUnit
/ reportUnit);
}
if (curTime - timeZero > HTTest.Duration * 1000) {
stopRun = true;
file_th.close();
file_finish.close();
file_latency.close();
}
}
long t1 = System.currentTimeMillis();
srcArray = new char[HTTest.ArraySize];
emptystr = new String(srcArray);
String str = emptystr.replace('\0', 'a');
q.add(str);
finishedUnit++;
long td = System.currentTimeMillis() - t1;
if (td > 50) {
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSSSS");
file_latency.println(ft.format(dNow) + "," + Long.toString(td));
}
}
}
}