Code Examples
A repository of 155 code examples for BeepBeep
MeasureThroughput.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package diagnose;
19 
20 import java.math.BigInteger;
21 
24 import ca.uqac.lif.cep.Connector;
25 import ca.uqac.lif.cep.ProcessorException;
26 import ca.uqac.lif.cep.diagnostics.Derivation;
27 import ca.uqac.lif.cep.diagnostics.ThroughputMeter;
28 import ca.uqac.lif.cep.diagnostics.WindowConsole;
29 import ca.uqac.lif.cep.functions.CumulativeFunction;
30 import ca.uqac.lif.cep.functions.Cumulate;
31 import ca.uqac.lif.cep.functions.ApplyFunction;
32 import ca.uqac.lif.cep.tmf.BlackHole;
33 import ca.uqac.lif.cep.tmf.QueueSource;
34 
35 /**
36  * Measure the number of events per second at some point in a
37  * processor chain.
38  * @author Sylvain HallĂ©
39  */
40 public class MeasureThroughput
41 {
42 
43  public static void main(String[] args) throws ProcessorException
44  {
45  /*
46  * We setup a counter that generates an increasing sequence of big
47  * integers, and which checks if each of the is prime. We don't care
48  * about the result for the purpose of this example, so we send it
49  * into a black hole.
50  */
51  QueueSource source = new QueueSource();
52  source.addEvent(new BigInteger("2"));
53  Cumulate counter = new Cumulate(new CumulativeFunction<BigInteger>(BigIntegerAdd.instance));
54  Connector.connect(source, counter);
55  ApplyFunction prime_check = new ApplyFunction(IsPrime.instance);
56  Connector.connect(counter, prime_check);
57  BlackHole sink = new BlackHole();
58  Connector.connect(prime_check, sink);
59 
60  /* Let's perform some diagnostics on this chain of processors. We
61  * would like to see the 1-second throughput inside the pipe between
62  * the prime_check and sink processors. The first step is to create
63  * a throughput meter. We instruct it to display its values in a window
64  * console, and to refresh its values every second. */
65  ThroughputMeter meter = new ThroughputMeter(new WindowConsole("Throughput"), 1000);
66 
67  /* We now install the meter between prime_check and sink. The nice
68  * part about the derivation is that it inserts itself automatically
69  * between two processors using the reconnect() method. If you want to
70  * stop using the derivation, just comment out the call to reconnect;
71  * you don't need to re-pipe the remaining processors. */
72  Derivation derivation = new Derivation(meter);
73  derivation.reconnect(prime_check, sink);
74 
75  /* Start the derivation and repeatedly push larger and larger numbers
76  * into the processor chain. */
77  derivation.start();
78  while (true)
79  {
80  source.push();
81  }
82  }
83 
84 }
Send events from one processor to another over a network.
Contains a few utility functions for manipulating Java&#39;s BigInteger objects.
Use HTTP gateways in push mode.
Measure the number of events per second at some point in a processor chain.
Compute twin primes by distributing the computation across two machines over a network.