Ejemplo n.º 1
0
  private void runAssertionPerformance(boolean namedWindow, EventRepresentationEnum outputType) {

    String eplCreate =
        namedWindow
            ? outputType.getAnnotationText()
                + " create window MyWindow.win:keepall() as (c1 string, c2 int)"
            : "create table MyWindow(c1 string primary key, c2 int)";
    EPStatement stmtNamedWindow = epService.getEPAdministrator().createEPL(eplCreate);
    assertEquals(outputType.getOutputClass(), stmtNamedWindow.getEventType().getUnderlyingType());

    // preload events
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "insert into MyWindow select theString as c1, intPrimitive as c2 from SupportBean");
    final int totalUpdated = 5000;
    for (int i = 0; i < totalUpdated; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 0));
    }
    stmt.destroy();

    String epl =
        "on SupportBean sb merge MyWindow nw where nw.c1 = sb.theString "
            + "when matched then update set nw.c2=sb.intPrimitive";
    stmt = epService.getEPAdministrator().createEPL(epl);
    stmt.addListener(mergeListener);

    // prime
    for (int i = 0; i < 100; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1));
    }
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < totalUpdated; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1));
    }
    long endTime = System.currentTimeMillis();
    long delta = endTime - startTime;

    // verify
    Iterator<EventBean> events = stmtNamedWindow.iterator();
    int count = 0;
    for (; events.hasNext(); ) {
      EventBean next = events.next();
      assertEquals(1, next.get("c2"));
      count++;
    }
    assertEquals(totalUpdated, count);
    assertTrue("Delta=" + delta, delta < 500);

    epService.getEPAdministrator().destroyAllStatements();
    epService.getEPAdministrator().getConfiguration().removeEventType("MyWindow", true);
  }
Ejemplo n.º 2
0
  public void update(EventBean[] newData, EventBean[] oldData) {

    //    	numRuns++;
    //    	if(numRuns % 1000 == 0)
    //        	System.out.println("PHONE CALL LISTENER: " + numRuns);

    if (!dc.stats.isStarted()) {
      dc.stats.start();
      StatsHolder.start();
    }

    Vote v = null;
    PhoneCall pc = (PhoneCall) newData[0].getUnderlying();
    LOG.debug("exec VoteSP\t" + pc.toParams());

    // IF WE'RE USING VOLT SPs
    if (dc instanceof VoltDBSPConnector) {
      v = ((VoltDBSPConnector) dc).runSP1(pc);
    }
    // OTHERWISE
    else {
      boolean exists = dc.realContestant(pc.contestantNumber);
      long numVotes = dc.numTimesVoted(pc.phoneNumber);
      String state = dc.getState(pc.phoneNumber);

      if (!exists) {
        dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
        dc.closeWorkflow(pc);
        return;
      }

      if (numVotes >= VoterConstants.MAX_VOTES) {
        dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
        dc.closeWorkflow(pc);
        return;
      }

      v = new Vote(pc, state, System.nanoTime());
      dc.insertVote(v);
    }

    dc.stats.addStat(VoterConstants.VOTE_KEY, pc);
    if (v != null) {
      v.startTime = System.nanoTime();

      EPRuntime cepRT = epService.getEPRuntime();
      cepRT.sendEvent(v);
    } else {
      dc.closeWorkflow(pc);
    }
  }
Ejemplo n.º 3
0
  public static Double computeDoubleMedian(double[] values) {

    if ((values == null) || (values.length == 0)) {
      return null;
    }
    double[] copy = new double[values.length];
    System.arraycopy(values, 0, copy, 0, values.length);
    Arrays.sort(copy);

    if ((copy.length % 2) == 0) {
      int middleIndex = copy.length / 2;
      double left = copy[middleIndex - 1];
      double right = copy[middleIndex];
      return (right + left) / 2.0;
    }

    int middleIndex = copy.length / 2;
    return copy[middleIndex];
  }