Example #1
0
int main(int argc, char ** argv)
{
  udpt = udp_throw_init(0);

  if (!udpt) {
    fprintf(stderr,"ERROR: unable to generate data\n");
    return -1;
  }
    
  read_cmd_options(argc,argv);

  // initialize RNG and seeds
  // use different keyoffsets in parallel, so key spaces are disjoint

  if (!kseed) kseed = (unsigned int) time(NULL);
  kseed += whichgen;
  vseed += whichgen;
  srand(kseed);
  keyoffset += whichgen*keyoffset;

  // create power-law distribution

  fprintf(stdout,"initializing power-law distribution ...\n");
  power_law_distribution_t * power = 
    power_law_initialize(concentration,maxkeys,RAND_MAX);
  
  // packet buffer length of 64 bytes per datum is ample

  int buflen = 64*perpacket;
  char *buf = (char *) malloc(buflen*sizeof(char));
  memset(buf,0,buflen);

  // generate the datums in packets

  fprintf(stdout,"starting generator ...\n");
  fflush(stdout);

  // plot
  //int *ycount = (int *) malloc(maxkeys*sizeof(int));
  //for (int i = 0; i < maxkeys; i++) ycount[i] = 0;

  double timestart = myclock();

  for (uint64_t i = 0; i < npacket; i++) {

    // packet header

    int offset = snprintf(buf,buflen,"packet %" PRIu64 "\n",i*numgen+whichgen);

    // generate one packet with perpacket datums

    uint64_t key;
    for (int j = 0; j < perpacket; j++) {
      uint64_t rn = rand_r(&kseed);
      while ((key = power_law_simulate(rn,power)) >= maxkeys)
        rn = rand_r(&kseed);

      // plot
      //ycount[key]++;

      key += keyoffset;
      uint32_t value = 0;
      uint32_t bias = 0;
      if ((evahash((uint8_t*) &key,sizeof(uint64_t),mask) & 0xFF) == 0x11) {
        bias = 1;
        value = ((rand_r(&vseed) & 0xF) == 0);
      } else value = rand_r(&vseed) & 0x1;

      offset += snprintf(buf+offset,buflen-offset,
                         "%" PRIu64 ",%u,%u\n",key,value,bias);
    }

    // write packet to UDP port(s)

    udp_throw_data(udpt,buf,offset);

    // sleep if rate is throttled 

    if (rate) {
      double n = 1.0*(i+1)*perpacket;
      double elapsed = myclock() - timestart;
      double actual_rate = n/elapsed;
      if (actual_rate > rate) {
        double delay = n/rate - elapsed;
        usleep(1.0e6*delay);
      }
    }
  }

  double timestop = myclock();

  // plot
  //FILE *fp = fopen("tmp.plot","w");
  //for (int i = 0; i < maxkeys; i++) 
  //  fprintf(fp,"%d %d\n",i,ycount[i]);
  //fclose(fp);

  uint64_t ndatum = npacket * perpacket;
  fprintf(stdout,"packets emitted = %" PRIu64 "\n",npacket);
  fprintf(stdout,"datums emitted = %" PRIu64 "\n",ndatum);
  fprintf(stdout,"elapsed time (secs) = %g\n",timestop-timestart);
  fprintf(stdout,"generation rate (datums/sec) = %g\n",
          ndatum/(timestop-timestart));
  fclose(stdout);

  power_law_destroy(power);

  // loop on sending one-integer STOP packets, STOPRATE per sec
  // allows receivers to shut down cleanly, even if behind

  int offset = snprintf(buf,buflen,"%d\n",whichgen);
  while (1) {
    udp_throw_data(udpt,buf,offset);
    usleep(1000000/STOPRATE);
  }

  udp_throw_destroy(udpt);

  return 0;
}
Example #2
0
int main(int argc, char **argv)
{
  udpt = udp_throw_init(0);

  if (!udpt) {
    fprintf(stderr,"ERROR: unable to generate data\n");
    return -1;
  }

  read_cmd_options(argc,argv);
  
  // initialize RNG and seeds
  // using different kseed in parallel will create disjoint key spaces

  if (!kseed) kseed = (unsigned int) time(NULL);
  kseed += whichgen;
  vseed += whichgen;
  srand(kseed);

  // create active set

  fprintf(stdout,"building active set ...\n");
  active_ring_t *aring = build_rings(16384,NACTIVE,65536,kseed,vseed,mask);

  // packet buffer length of 64 bytes per datum is ample

  int buflen = 64*perpacket;
  char *buf = (char *) malloc(buflen*sizeof(char));
  memset(buf,0,buflen);

  // generate the datums in packets

  fprintf(stdout,"starting generator ...\n");
  fflush(stdout);

  double timestart = myclock();

  for (uint64_t i = 0; i < npacket; i++) {

    // packet header

    int offset = snprintf(buf,buflen,"packet %" PRIu64 "\n",i*numgen+whichgen);

    // create packet containing perpacket datums

    offset = print_packet(aring,perpacket,buf,buflen,offset);

    // write the packet to UDP port(s)

    udp_throw_data(udpt,buf,offset);

    // sleep if rate is throttled 

    if (rate) {
      double n = 1.0*(i+1)*perpacket;
      double elapsed = myclock() - timestart;
      double actual_rate = n/elapsed;
      if (actual_rate > rate) {
        double delay = n/rate - elapsed;
        usleep(1.0e6*delay);
      }
    }
  }
  
  double timestop = myclock();

  print_stats(aring);
  uint64_t ndatum = npacket * perpacket;
  fprintf(stdout,"packets emitted = %" PRIu64 "\n",npacket);
  fprintf(stdout,"datums emitted = %" PRIu64 "\n",ndatum);
  fprintf(stdout,"elapsed time (secs) = %g\n",timestop-timestart);
  fprintf(stdout,"generation rate (datums/sec) = %g\n",
          ndatum/(timestop-timestart));
  fclose(stdout);

  // loop on sending one-integer STOP packets, STOPRATE per sec
  // allows receivers to shut down cleanly, even if behind

  int offset = snprintf(buf,buflen,"%d\n",whichgen);
  while (1) {
    udp_throw_data(udpt,buf,offset);
    usleep(1000000/STOPRATE);
  }

  udp_throw_destroy(udpt);

  return 0;
}