Skip to content

Commit 93ab9ed

Browse files
committed
lower locks, only engine-process tag-0
1 parent 5139d2b commit 93ab9ed

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconMutil.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
*/
4646
final class ReconMutil {
4747

48-
boolean DEBUG = true;
49-
5048
// Performance parameters:
5149
final int BENCH_SECONDS = 30;
5250
final int EVENTS_PER_CHUNK = 10;
@@ -82,16 +80,15 @@ final class ReconMutil {
8280

8381
// Progress counters:
8482
volatile int readEvents;
85-
volatile int writeEvents;
8683
volatile int failEvents;
8784
volatile int fileEvents;
8885
volatile int maxFileEvents;
86+
volatile int writeEvents;
8987
volatile AtomicInteger taggedEvents = new AtomicInteger();
9088
volatile ProgressPrintout progress = new ProgressPrintout();
9189

9290
// Control flags:
9391
AtomicBoolean paused = new AtomicBoolean(true);
94-
9592
final Object serialLock = new Object();
9693

9794
ReconMutil(OptionParser parser) {
@@ -129,9 +126,9 @@ void launch(int[] threads, String output, String... input) {
129126
// wait for finish:
130127
while (!writerThread.isDone()) {
131128
sleep(5000);
132-
if (DEBUG) show();
133129
for (CompletableFuture f : decoThreads) if (f.isDone()) decoThreads.remove(f);
134130
for (CompletableFuture f : procThreads) if (f.isDone()) procThreads.remove(f);
131+
if (true) show();
135132
}
136133
}
137134

@@ -148,7 +145,7 @@ void read(int threads, String... input) {
148145
List<Object> output = new ArrayList<>(EVENTS_PER_CHUNK);
149146

150147
// loop over input events:
151-
while ( (maxEvents < 1 || readEvents < maxEvents) &&
148+
while ( (maxEvents < 1 || writeEvents < maxEvents+taggedEvents.get()) &&
152149
(maxFileEvents < 1 || fileEvents < maxFileEvents) ) {
153150

154151
if (reader != null) {
@@ -198,19 +195,19 @@ void decode(int thread) {
198195
List<HipoDataEvent> output = new ArrayList<>(input.size());
199196
for (int i=0; i<input.size(); i++) {
200197
HipoDataEvent event = input.get(i) instanceof ByteBuffer
201-
? decode((ByteBuffer)input.get(i))
198+
? decode(thread, (ByteBuffer)input.get(i))
202199
: new HipoDataEvent(((Event)input.get(i)), schema);
203200
output.add(event);
204201
Benchmark.getInstance().resume(thread, "serial");
205202
Event tag;
206203
synchronized (serialLock) {
207204
tag = serial.read(event.getHipoEvent());
208-
if (thread == 0 && ++serials > reload) {
209-
updateHelicity();
210-
serials = 0;
211-
reload += 10 * reloads * minReload;
212-
reloads++;
213-
}
205+
}
206+
if (thread == 0 && ++serials > reload) {
207+
updateHelicity();
208+
serials = 0;
209+
reload += 10 * reloads * minReload;
210+
reloads++;
214211
}
215212
if (!tag.isEmpty()) {
216213
output.add(new HipoDataEvent(tag, schema));
@@ -221,15 +218,15 @@ void decode(int thread) {
221218
procQueue.offer(output);
222219
}
223220
}
224-
synchronized (serialLock) {
225-
if (thread == 0) updateHelicity();
226-
}
221+
if (thread == 0) updateHelicity();
227222
}
228223

229224
void updateHelicity() {
230225
paused.set(true);
231226
sleep(1000);
232-
serial.updateHelicitySequence();
227+
synchronized (serialLock) {
228+
serial.updateHelicitySequence();
229+
}
233230
paused.set(false);
234231
}
235232

@@ -239,25 +236,29 @@ void updateHelicity() {
239236
*/
240237
void process(int thread) {
241238
while (true) {
239+
if (maxEvents > 0 && writeEvents > maxEvents+taggedEvents.get()) {
240+
readerThread.cancel(true);
241+
break;
242+
}
242243
List<HipoDataEvent> input = procQueue.poll();
243244
if (input == null) {
244245
if (procQueue.isEmpty() && decoThreads.isEmpty() && procQueue.isEmpty()) {
245-
if (writeEvents+skipEvents+failEvents >= readEvents+taggedEvents.get()) {
246-
System.out.println("recon-mutil:: processor thread #"+thread+" exiting.");
246+
if (writeEvents+skipEvents+failEvents >= readEvents+taggedEvents.get())
247247
break;
248-
}
249248
}
250249
sleep(100);
251250
}
252251
else {
253252
//if (rethreadThread != null && !rethreadThread.isDone()) readQueue.offer(o);
254253
List<Event> output = new ArrayList<>(input.size());
255254
for (int i=0; i<input.size(); i++) {
256-
for (Map.Entry<String,ReconstructionEngine> engine : engines.entrySet()) {
257-
Benchmark.getInstance().resume(thread, engine.getKey());
258-
try { engine.getValue().processDataEvent(input.get(i)); }
259-
catch (Exception ex) { ex.printStackTrace(); }
260-
Benchmark.getInstance().pause(thread, engine.getKey());
255+
if (input.get(i).getHipoEvent().getEventTag() == 0) {
256+
for (Map.Entry<String,ReconstructionEngine> engine : engines.entrySet()) {
257+
Benchmark.getInstance().resume(thread, engine.getKey());
258+
try { engine.getValue().processDataEvent(input.get(i)); }
259+
catch (Exception ex) { ex.printStackTrace(); }
260+
Benchmark.getInstance().pause(thread, engine.getKey());
261+
}
261262
}
262263
output.add(input.get(i).getHipoEvent());
263264
}
@@ -338,15 +339,15 @@ void rethread(int seconds, int... threads) {
338339
* @param bytes the EVIO byte buffer
339340
* @return decoded event
340341
*/
341-
HipoDataEvent decode(ByteBuffer bytes) {
342-
Benchmark.getInstance().resume("evio");
342+
HipoDataEvent decode(int thread, ByteBuffer bytes) {
343+
Benchmark.getInstance().resume(thread, "evio");
343344
EvioDataEvent evio = new EvioDataEvent(bytes.array(), ByteOrder.LITTLE_ENDIAN);
344-
Benchmark.getInstance().pause("evio");
345-
Benchmark.getInstance().resume("deco");
345+
Benchmark.getInstance().pause(thread, "evio");
346+
Benchmark.getInstance().resume(thread, "deco");
346347
CLASDecoder d = decoders.take();
347348
HipoDataEvent hipo = d.getDecodedDataEvenet(evio);
348349
decoders.put(d);
349-
Benchmark.getInstance().pause("deco");
350+
Benchmark.getInstance().pause(thread, "deco");
350351
return hipo;
351352
}
352353

0 commit comments

Comments
 (0)