-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLatencyTest.java
67 lines (61 loc) · 2.01 KB
/
LatencyTest.java
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
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
/**
* @deprecated
* This is a program that automatically retrives latency test results from egress.
* Also, this program reads from the old egress, which is not used anymore.
*/
public class LatencyTest {
/**
* Get the egress output corresponding with latency test
* @param url
* @return result: the response of the get request
* @throws Exception
*/
public static String get(String url) throws Exception {
URL serverUrl = new URL(url);
HttpURLConnection con = (HttpURLConnection) serverUrl.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode();
String result = "";
if (status == 200) {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream())
);
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
result = content.toString();
}
// System.out.println(result);
return result;
}
public static void main(String[] args) throws Exception {
String filename = "latencyTest.txt";
FileWriter filewriter = new FileWriter(filename);
PrintWriter printWriter = new PrintWriter(filewriter);
String url = "http://localhost:8091/add-edge-latency";
long start = System.currentTimeMillis();
long maxPeriod = 20 * 1000 * 60;
String egressOutput;
while (System.currentTimeMillis() - start < maxPeriod) {
egressOutput = get(url);
String[] parts = egressOutput.split(",");
// System.out.println(Arrays.toString(parts));
// we only need to record latency of one vertex as a representative
if (parts[0].equals("1")) {
printWriter.println(egressOutput);
}
// pull from egress every 100 milliseconds
Thread.sleep(5);
}
// close writer
printWriter.close();
}
}