MCPcopy Create free account
hub / github.com/e2wugui/zeze / main

Method main

ZezeJava/ZezeJavaTest/src/Benchmark/Simulate.java:120–216  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

118 }
119
120 public static void main(String[] args) throws Exception {
121 var lookup = MethodHandles.lookup();
122 for (var arg : args) {
123 var kv = arg.split("=");
124 if (kv.length == 2) {
125 var k = kv[0];
126 if (k.endsWith("Ip"))
127 lookup.findStaticVarHandle(Simulate.class, k, String.class).set(kv[1]);
128 else {
129 var v = Integer.parseInt(kv[1].replace("_", ""));
130 if (v < 0 || v == 0 && !k.endsWith("Weight") && !k.equals("localPercent"))
131 throw new IllegalArgumentException("invalid " + k + " = " + v);
132 lookup.findStaticVarHandle(Simulate.class, k, int.class).set(v);
133 }
134 }
135 }
136 var procs = new ArrayList<Proc>();
137 int totalWeight = 0;
138 for (var f : Simulate.class.getDeclaredFields()) {
139 if ((f.getType() == int.class || f.getType() == String.class) && Modifier.isStatic(f.getModifiers())) {
140 var k = f.getName();
141 Object v = lookup.unreflectVarHandle(f).get();
142 logger.info("{} = {}", k, v);
143 if (k.endsWith("Weight")) {
144 totalWeight += (int)v;
145 var name = k.substring(0, k.length() - 6);
146 var mh = lookup.findStatic(Simulate.class, name, MethodType.methodType(long.class));
147 procs.add(new Proc(name, mh, (int)v));
148 }
149 }
150 }
151 if (totalWeight <= 0)
152 throw new IllegalArgumentException("invalid totalWeight = " + totalWeight);
153 var totalWeight0 = totalWeight;
154 keyBegin = (long)localKeyRange * serverId;
155 keyEnd = keyBegin + localKeyRange;
156 keyWindowBegin.set(keyBegin);
157
158 Task.initThreadPool(Task.newFixedThreadPool(taskThreadCount, "ZezeTaskPool"),
159 Executors.newScheduledThreadPool(schdThreadCount, new ThreadFactory("ZezeScheduledPool")));
160
161 var app = new SimpleApp(serverId, 20000 + serverId + 1, 20000);
162 app.getZeze().addTable("", table5 = new Table5());
163 app.start();
164
165 var totalCount = new AtomicLong();
166 var lastTime = new AtomicLong(System.nanoTime());
167 var state = new Object() {
168 long lastCount;
169 };
170 for (int i = 0; i < concurrentProcs; i++) {
171 var t = new Thread(() -> {
172 try {
173 for (; ; ) {
174 var r = ThreadLocalRandom.current().nextInt(totalWeight0);
175 Proc proc = null;
176 for (var p : procs) {
177 if ((r -= p.weight) < 0) {

Callers

nothing calls this directly

Calls 15

initThreadPoolMethod · 0.95
newFixedThreadPoolMethod · 0.95
getZezeMethod · 0.95
startMethod · 0.95
parseIntMethod · 0.80
getDeclaredFieldsMethod · 0.80
currentMethod · 0.80
formatMethod · 0.80
replaceMethod · 0.65
equalsMethod · 0.65
getTypeMethod · 0.65
getNameMethod · 0.65

Tested by

no test coverage detected