-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (34 loc) · 1.46 KB
/
Copy pathMain.java
File metadata and controls
45 lines (34 loc) · 1.46 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
import java.util.concurrent.ArrayBlockingQueue;
public class Main {
private static final boolean ENABLE_ANALYTICS = false;
private static final boolean ENABLE_STORAGE = false;
public static void main(String[] args) throws InterruptedException {
ArrayBlockingQueue<Order> queue = new ArrayBlockingQueue<>(200_000);
MatchingEngine engine = new MatchingEngine(queue);
if (ENABLE_ANALYTICS) {
AnalyticsModule analytics = new AnalyticsModule();
analytics.start();
engine.setAnalytics(analytics);
}
if (ENABLE_STORAGE) {
StorageLayer storage = new StorageLayer();
storage.start();
engine.setStorage(storage);
}
int total = 10_000_000;
ProducerThread p1 = new ProducerThread(queue, "P1", total / 3);
ProducerThread p2 = new ProducerThread(queue, "P2", total / 3);
ProducerThread p3 = new ProducerThread(queue, "P3", total / 3);
System.out.println(">>> STARTING 10M ORDER STRESS TEST...");
long start = System.currentTimeMillis();
engine.start();
p1.start(); p2.start(); p3.start();
p1.join(); p2.join(); p3.join();
queue.put(Order.POISON_PILL);
engine.join();
long end = System.currentTimeMillis();
double sec = (end - start) / 1000.0;
System.out.printf("%nTime: %.3fs | Throughput: %,.0f orders/sec%n",
sec, total / sec);
}
}