/* the loop of the main thread, wait the work threads to complete */
static void ms_monitor_slap_mode()
{
  int second= 0;

  if(pthread_barrier_init(&barr, NULL, ms_setting.nthreads))
  {
      fprintf(stderr,"Could not create a barrier\n");
      exit(1);
  }
  if(pthread_barrier_init(&barr_warmup, NULL, ms_setting.nthreads+1))
  {
      fprintf(stderr,"Could not create a barrier\n");
      exit(1);
  }
  /* Wait all the threads complete initialization. */
  pthread_mutex_lock(&ms_global.init_lock.lock);
  while (ms_global.init_lock.count < ms_setting.nthreads)
  {
    pthread_cond_wait(&ms_global.init_lock.cond,
                      &ms_global.init_lock.lock);
  }
  pthread_mutex_unlock(&ms_global.init_lock.lock);


  /* Warm up always: even if there are set operations scheduled */
  {
    fprintf(stderr,"Warming up\n");
    /* Wait all the connects complete warm up. */
    pthread_mutex_lock(&ms_global.warmup_lock.lock);
    while (ms_global.warmup_lock.count + 0 < ms_stats.active_conns )
    {
      pthread_cond_wait(&ms_global.warmup_lock.cond, &ms_global.warmup_lock.lock);
    }
    pthread_mutex_unlock(&ms_global.warmup_lock.lock);
    fprintf(stderr,"Warmup finished\n");
    /* TODO: BUG: warm up not always finishes */
  }
  fprintf(stderr,"Run time %d\n", ms_setting.run_time);
  kill(ms_setting.ppid?ms_setting.ppid:getppid(), SIGUSR2);
  while (!can_go) {
    usleep(1000);
  }
  ms_global.finish_warmup= true;
  clear_SLA_stats();
  ms_statistic_clear();
  ms_stats.cmd_get = 0;
  ms_stats.cmd_set = 0;
  /* running in "run time" mode, user specify run time */
  if (ms_setting.run_time > 0)
  {
    gettimeofday(&start_time, NULL);
    while (can_go)
    {
      sleep(1);
      second++;

      if ((ms_setting.stat_freq > 0) && (second % ms_setting.stat_freq == 0)
          && (ms_stats.active_conns >= ms_setting.nconns)
          && (ms_stats.active_conns <= INT_MAX))
      {
        ms_print_statistics(second);
      }

      if (ms_setting.run_time <= second)
      {
        ms_global.time_out= true;
        break;
      }

      /* all connections disconnect */
      if ((second > 5) && (ms_stats.active_conns == 0))
      {
        break;
      }
    }
    gettimeofday(&end_time, NULL);
    sleep(1);       /* wait all threads clean up */
  }
  else
  {
    /* running in "execute number" mode, user specify execute number */
    gettimeofday(&start_time, NULL);

    /*
     * We loop until we know that all connects have cleaned up.
     */
    pthread_mutex_lock(&ms_global.run_lock.lock);
    while (ms_global.run_lock.count < ms_setting.nconns)
    {
      pthread_cond_wait(&ms_global.run_lock.cond, &ms_global.run_lock.lock);
    }
    pthread_mutex_unlock(&ms_global.run_lock.lock);

    gettimeofday(&end_time, NULL);
  }

  ms_print_memslap_stats(&start_time, &end_time);
  print_SLA_stats();
} /* ms_monitor_slap_mode */
Exemple #2
0
/* the loop of the main thread, wait the work threads to complete */
static void ms_monitor_slap_mode()
{
  int second= 0;
  struct timeval start_time, end_time;

  /* Wait all the threads complete initialization. */
  pthread_mutex_lock(&ms_global.init_lock.lock);
  while (ms_global.init_lock.count < ms_setting.nthreads)
  {
    pthread_cond_wait(&ms_global.init_lock.cond,
                      &ms_global.init_lock.lock);
  }
  pthread_mutex_unlock(&ms_global.init_lock.lock);

  /* only when there is no set operation it need warm up */
  if (ms_setting.cmd_distr[CMD_SET].cmd_prop < PROP_ERROR)
  {
    /* Wait all the connects complete warm up. */
    pthread_mutex_lock(&ms_global.warmup_lock.lock);
    while (ms_global.warmup_lock.count < ms_setting.nconns)
    {
      pthread_cond_wait(&ms_global.warmup_lock.cond, &ms_global.warmup_lock.lock);
    }
    pthread_mutex_unlock(&ms_global.warmup_lock.lock);
  }
  ms_global.finish_warmup= true;

  /* running in "run time" mode, user specify run time */
  if (ms_setting.run_time > 0)
  {
    gettimeofday(&start_time, NULL);
    while (1)
    {
      sleep(1);
      second++;

      if ((ms_setting.stat_freq > 0) && (second % ms_setting.stat_freq == 0)
          && (ms_stats.active_conns >= ms_setting.nconns)
          && (ms_stats.active_conns <= INT_MAX))
      {
        ms_print_statistics(second);
      }

      if (ms_setting.run_time <= second)
      {
        ms_global.time_out= true;
        break;
      }

      /* all connections disconnect */
      if ((second > 5) && (ms_stats.active_conns == 0))
      {
        break;
      }
    }
    gettimeofday(&end_time, NULL);
    sleep(1);       /* wait all threads clean up */
  }
  else
  {
    /* running in "execute number" mode, user specify execute number */
    gettimeofday(&start_time, NULL);

    /*
     * We loop until we know that all connects have cleaned up.
     */
    pthread_mutex_lock(&ms_global.run_lock.lock);
    while (ms_global.run_lock.count < ms_setting.nconns)
    {
      pthread_cond_wait(&ms_global.run_lock.cond, &ms_global.run_lock.lock);
    }
    pthread_mutex_unlock(&ms_global.run_lock.lock);

    gettimeofday(&end_time, NULL);
  }

  ms_print_memslap_stats(&start_time, &end_time);
} /* ms_monitor_slap_mode */