Beispiel #1
0
static int
noit_console_show_fq(noit_console_closure_t ncct,
                     int argc, char **argv,
                     noit_console_state_t *dstate,
                     void *closure) {
  int i;
  nc_printf(ncct, " == FQ ==\n");
  nc_printf(ncct, " Allocation Failures:   %llu\n", global_fq_ctx.allocation_failures);
  nc_printf(ncct, " Messages:              %llu\n", global_fq_ctx.msg_cnt);
  for(i=0; i<global_fq_ctx.nhosts; i++) {
    fq_stats_t *s = &global_fq_ctx.stats[i];
    nc_printf(ncct, " === %s:%d ===\n", global_fq_ctx.hostname[i],
              global_fq_ctx.ports[i]);
    nc_printf(ncct, "  publications:         %llu\n", s->publications);
    nc_printf(ncct, "  client_tx_drop:       %llu\n", s->client_tx_drop);
    nc_printf(ncct, "  error_messages:       %llu\n", s->error_messages);
    nc_printf(ncct, "  no_exchange:          %llu\n", s->no_exchange);
    nc_printf(ncct, "  no_route:             %llu\n", s->no_route);
    nc_printf(ncct, "  routed:               %llu\n", s->routed);
    nc_printf(ncct, "  dropped:              %llu\n", s->dropped);
    nc_printf(ncct, "  msgs_in:              %llu\n", s->msgs_in);
    nc_printf(ncct, "  msgs_out:             %llu\n", s->msgs_out);
    nc_printf(ncct, "  client_tx_backlog:    %llu\n",
              fq_client_data_backlog(global_fq_ctx.client[i]));
  }
  return 1;
}
Beispiel #2
0
static void
print_rate(fq_client c, hrtime_t s, hrtime_t f, uint64_t cnt, uint64_t icnt) {
  double d;
  if(cnt) {
    d = (double)cnt * 1000000000;
    d /= (double)(f-s);
    printf("[%d backlog] output %0.2f msg/sec\n",
           fq_client_data_backlog(c), d);
  }
  if(icnt) {
    d = (double)icnt * 1000000000;
    d /= (double)(f-s);
    printf("[%d backlog]  input %0.2f msg/sec\n",
           fq_client_data_backlog(c), d);
  }
}
Beispiel #3
0
int main(int argc, char **argv) {
  hrtime_t s0, s, f, f0;
  uint64_t cnt = 0, icnt = 0;
  int psize = 0, i = 0;
  fq_client c;
  fq_msg *m;
  char *fq_debug = getenv("FQ_DEBUG");
  if(fq_debug) fq_debug_set_bits(atoi(fq_debug));
  signal(SIGPIPE, SIG_IGN);
  fq_client_init(&c, 0, logger);
  if(argc < 5) {
    fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n",
            argv[0]);
    exit(-1);
  }
  fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]);
  fq_client_heartbeat(c, 1000);
  fq_client_set_backlog(c, 10000, 100);
  fq_client_connect(c);

  if(argc > 5) {
     psize = atoi(argv[5]);
  }
  printf("payload size -> %d\n", psize);
  if(argc > 6) {
    send_count = atoi(argv[6]);
  }
  printf("message count -> %d\n", send_count);

  s0 = s = fq_gethrtime();
  while(i < send_count || fq_client_data_backlog(c) > 0) {
    if(i < send_count) {
      m = fq_msg_alloc_BLANK(psize);
      memset(m->payload, 0, psize);
      fq_msg_exchange(m, "maryland", 8);
      fq_msg_route(m, "test.prefix.boo", 15);
      fq_msg_id(m, NULL);
      fq_client_publish(c, m);
      cnt++;
      i++;
      fq_msg_free(m);
    }
    else usleep(100);


    f = fq_gethrtime();
    if(f-s > 1000000000) {
      print_rate(c, s, f, cnt, icnt);
      icnt = 0;
      cnt = 0;
      s = f;
    }
  }
  f0 = fq_gethrtime();
  print_rate(c, s0, f0, i, 0);
  (void) argc;
  return 0;
}
Beispiel #4
0
Datei: fqc.c Projekt: denji/fq
int main(int argc, char **argv) {
  hrtime_t s0, s, f, f0;
  uint64_t cnt = 0, icnt = 0;
  int psize = 0, i = 0, rcvd = 0;
  fq_client c;
  fq_bind_req breq;
  fq_msg *m;
  signal(SIGPIPE, SIG_IGN);
  fq_client_init(&c, 0, logger);
  if(argc < 5) {
    fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n",
            argv[0]);
    exit(-1);
  }
  fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]);
  fq_client_heartbeat(c, 1000);
  fq_client_set_backlog(c, 10000, 100);
  fq_client_connect(c);

  memset(&breq, 0, sizeof(breq));
  memcpy(breq.exchange.name, "maryland", 8);
  breq.exchange.len = 8;
  breq.peermode = 0;
  breq.program = (char *)"prefix:\"test.prefix.\"";

  fq_client_bind(c, &breq);
  while(breq.out__route_id == 0) usleep(100);
  printf("route set -> %u\n", breq.out__route_id);
  if(breq.out__route_id == FQ_BIND_ILLEGAL) {
    fprintf(stderr, "Failure to bind...\n");
    exit(-1);
  }

  if(argc > 5) {
     psize = atoi(argv[5]);
  }
  printf("payload size -> %d\n", psize);
  if(argc > 6) {
    send_count = atoi(argv[6]);
  }
  printf("message count -> %d\n", send_count);

  s0 = s = fq_gethrtime();
  while(i < send_count || fq_client_data_backlog(c) > 0) {
    if(i < send_count) {
      m = fq_msg_alloc_BLANK(psize);
      memset(m->payload, 0, psize);
      fq_msg_exchange(m, "maryland", 8);
      fq_msg_route(m, "test.prefix.foo", 15);
      fq_msg_id(m, NULL);
      fq_client_publish(c, m);
      cnt++;
      i++;
      fq_msg_free(m);
    }
    else usleep(100);


    f = fq_gethrtime();
    while(m = fq_client_receive(c)) {
      icnt++;
      rcvd++;
      fq_msg_deref(m);
    }
    if(f-s > 1000000000) {
      print_rate(c, s, f, cnt, icnt);
      icnt = 0;
      cnt = 0;
      s = f;
    }
  }
  f0 = fq_gethrtime();
  print_rate(c, s0, f0, i, 0);
  do {
    icnt=0;
    while(m = fq_client_receive(c)) {
      icnt++;
      rcvd++;
      fq_msg_deref(m);
    }
  } while(rcvd < send_count);
  f0 = fq_gethrtime();
  print_rate(c, s0, f0, 0, rcvd);
  printf("Total received during test: %d\n", rcvd);

  (void) argc;
  return 0;
}
Beispiel #5
0
int main(int argc, char **argv) {
  char *host = NULL, *exchange = NULL, *route = NULL;
  char *address = strdup("127.0.0.1:8765");
  char *user = "******";
  char *pass = "******";
  int port = 0;
  int c = 0;
  if (argc == 1) {
    usage(argv[0]);
    exit(-1);
  }
  while((c = getopt(argc, argv, "ha:x:r:u:p:")) != EOF) {
    switch(c) {
    case 'h':
      usage(argv[0]);
      exit(0);
      break;
    case 'a':
      address = strdup(optarg);
      break;
    case 'x':
      exchange = strdup(optarg);
      break;
    case 'r':
      route = strdup(optarg);
      break;
    case 'u':
      user = strdup(optarg);
      break;
    case 'p':
      pass = strdup(optarg);
      break;
    default:
      usage(argv[0]);
      exit(-1);
    }
  }
  // Separate host and port in address string
  // We have strdup'ed address so we can mutate it
  host = address;
  for (char *p = address; *p != 0; p++) {
    if (*p == ':') {
      *p = 0;
      port = strtol(p+1, NULL, 10);
      break;
    }
  }
  if (!port) {
    printf("Illegal port specification\n");
    exit(-1);
  }
  if (!exchange) {
    printf("Exchange argument required");
    exit(-1);
  }
  if (!route) {
    printf("Route argument required");
    exit(-1);
  }

  fq_client cli;
  fq_msg *m = NULL;
  size_t exchange_len = strlen(exchange);
  size_t route_len = strlen(route);
  signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE
  fq_client_init(&cli, 0, logger);
  fq_client_creds(cli, host, port, user, pass);
  fq_client_heartbeat(cli, 1000);
  fq_client_set_backlog(cli, 10000, 100);
  fq_client_connect(cli);
  while(true) {
    char *line = NULL;
    size_t line_cap = 0;
    int line_len;
    line_len = getline(&line, &line_cap, stdin);
    if(line_len < 0) {
      // wait for queues to drain
      while(fq_client_data_backlog(cli) > 0) {
        usleep(100);
      }
      exit(0);
    }
    m = fq_msg_alloc(line, line_len);
    fq_msg_exchange(m, exchange, exchange_len);
    fq_msg_route(m, route, route_len);
    fq_msg_id(m, NULL);
    fq_client_publish(cli, m);
    fq_msg_free(m);
  }
  return 0;
}