Back to index

nordugrid-arc-nox  1.1.0~rc6
Functions | Variables
perftest_deleg_bydelegclient.cpp File Reference
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <glibmm/thread.h>
#include <glibmm/timer.h>
#include <arc/GUID.h>
#include <arc/ArcConfig.h>
#include <arc/Logger.h>
#include <arc/URL.h>
#include <arc/message/PayloadSOAP.h>
#include <arc/message/MCC.h>
#include <arc/client/ClientInterface.h>
#include <arc/client/ClientX509Delegation.h>

Go to the source code of this file.

Functions

int Round (double x)
void sendRequests ()
int main (int argc, char *argv[])

Variables

Glib::Mutex * mutex
bool run
int finishedThreads
unsigned long completedRequests
unsigned long failedRequests
unsigned long totalRequests
Glib::TimeVal completedTime
Glib::TimeVal failedTime
Glib::TimeVal totalTime
std::string url_str

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 105 of file perftest_deleg_bydelegclient.cpp.

                                {
  // Some variables...
  int numberOfThreads;
  int duration;
  int i;
  Glib::Thread** threads;
  const char* config_file = NULL;
  int debug_level = -1;
  Arc::LogStream logcerr(std::cerr);

  // Process options - quick hack, must use Glib options later
  while(argc >= 3) {
    if(strcmp(argv[1],"-c") == 0) {
      config_file = argv[2];
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-d") == 0) {
      debug_level=Arc::string_to_level(argv[2]);
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else {
      break;
    };
  } 
  if(debug_level >= 0) {
    Arc::Logger::getRootLogger().setThreshold((Arc::LogLevel)debug_level);
    Arc::Logger::getRootLogger().addDestination(logcerr);
  }
  // Extract command line arguments.
  if (argc!=4){
    std::cerr << "Wrong number of arguments!" << std::endl
             << std::endl
             << "Usage:" << std::endl
             << "perftest_deleg_bydelegclient [-c config] [-d debug] url threads duration" << std::endl
             << std::endl
             << "Arguments:" << std::endl
             << "url     The url of the delegation service." << std::endl
             << "threads  The number of concurrent requests." << std::endl
             << "duration The duration of the test in seconds." << std::endl
             << "config   The file containing client chain XML configuration with " << std::endl
              << "         'soap' entry point and HOSTNAME, PORTNUMBER and PATH " << std::endl
              << "         keyword for hostname, port and HTTP path of 'echo' service." << std::endl
             << "debug    The textual representation of desired debug level. Available " << std::endl
              << "         levels: DEBUG, VERBOSE, INFO, WARNING, ERROR, FATAL." << std::endl;
    exit(EXIT_FAILURE);
  }
  url_str = std::string(argv[1]);
  numberOfThreads = atoi(argv[2]);
  duration = atoi(argv[3]);

  // Start threads.
  run=true;
  finishedThreads=0;
  //Glib::thread_init();
  mutex=new Glib::Mutex;
  threads = new Glib::Thread*[numberOfThreads];
  for (i=0; i<numberOfThreads; i++)
    threads[i]=Glib::Thread::create(sigc::ptr_fun(sendRequests),true);

  // Sleep while the threads are working.
  Glib::usleep(duration*1000000);

  // Stop the threads
  run=false;
  while(finishedThreads<numberOfThreads)
    Glib::usleep(100000);

  // Print the result of the test.
  Glib::Mutex::Lock lock(*mutex);
  totalRequests = completedRequests+failedRequests;
  totalTime = completedTime+failedTime;
  std::cout << "========================================" << std::endl;
  std::cout << "URL: "
           << url_str << std::endl;
  std::cout << "Number of threads: "
           << numberOfThreads << std::endl;
  std::cout << "Duration: "
           << duration << " s" << std::endl;
  std::cout << "Number of requests: "
           << totalRequests << std::endl;
  std::cout << "Completed requests: "
           << completedRequests << " ("
           << Round(completedRequests*100.0/totalRequests)
           << "%)" << std::endl;
  std::cout << "Failed requests: "
           << failedRequests << " ("
           << Round(failedRequests*100.0/totalRequests)
           << "%)" << std::endl;
  std::cout << "Average response time for all requests: "
           << Round(1000*totalTime.as_double()/totalRequests)
           << " ms" << std::endl;
  if (completedRequests!=0)
    std::cout << "Average response time for completed requests: "
             << Round(1000*completedTime.as_double()/completedRequests)
             << " ms" << std::endl;
  if (failedRequests!=0)
    std::cout << "Average response time for failed requests: "
             << Round(1000*failedTime.as_double()/failedRequests)
             << " ms" << std::endl;
  std::cout << "========================================" << std::endl;

  return 0;
}

Here is the call graph for this function:

int Round ( double  x)

Definition at line 36 of file perftest_deleg_bydelegclient.cpp.

                   {
  return int(x+0.5);
}
void sendRequests ( )

Definition at line 41 of file perftest_deleg_bydelegclient.cpp.

                   {
  // Some variables...
  unsigned long completedRequests = 0;
  unsigned long failedRequests = 0;
  Glib::TimeVal completedTime(0,0);
  Glib::TimeVal failedTime(0,0);
  Glib::TimeVal tBefore;
  Glib::TimeVal tAfter;
  bool connected;

  //std::string url_str("https://127.0.0.1:60000/echo");
  Arc::URL url(url_str);

  Arc::MCCConfig mcc_cfg;
  mcc_cfg.AddPrivateKey("../echo/userkey-nopass.pem");
  mcc_cfg.AddCertificate("../echo/usercert.pem");
  mcc_cfg.AddCAFile("../echo/testcacert.pem");
  mcc_cfg.AddCADir("../echo/certificates");
  
  while(run){
    
    // Create a Client.
    Arc::ClientX509Delegation *client = NULL;
    client = new Arc::ClientX509Delegation(mcc_cfg,url);

    connected=true;
    while(run and connected){
      // Send the delegation request and time it.
      tBefore.assign_current_time();
      std::string arc_delegation_id;
      bool res;
      if(client) {
        if(!(res = client->createDelegation(Arc::DELEG_ARC, arc_delegation_id))) {
          std::cerr<<"Delegation to ARC delegation service failed"<<std::endl;
        }
      }
      tAfter.assign_current_time();

      if(!res) {
        // The delegation has not succeeded.
        failedRequests++;
        failedTime+=tAfter-tBefore;
        connected=false;
      }
      else {
        // Everything worked just fine.
        std::cout<<"Delegation ID: "<<arc_delegation_id<<std::endl;
        completedRequests++;
        completedTime+=tAfter-tBefore;
      }
    }
    if(client) delete client;
  }

  // Update global variables.
  Glib::Mutex::Lock lock(*mutex);
  ::completedRequests+=completedRequests;
  ::failedRequests+=failedRequests;
  ::completedTime+=completedTime;
  ::failedTime+=failedTime;
  finishedThreads++;
  std::cout << "Number of finished threads: " << finishedThreads << std::endl;
}

Here is the call graph for this function:


Variable Documentation

unsigned long completedRequests

Definition at line 27 of file perftest_deleg_bydelegclient.cpp.

Glib::TimeVal completedTime

Definition at line 30 of file perftest_deleg_bydelegclient.cpp.

unsigned long failedRequests

Definition at line 28 of file perftest_deleg_bydelegclient.cpp.

Glib::TimeVal failedTime

Definition at line 31 of file perftest_deleg_bydelegclient.cpp.

Definition at line 26 of file perftest_deleg_bydelegclient.cpp.

Glib::Mutex* mutex

Definition at line 24 of file perftest_deleg_bydelegclient.cpp.

bool run

Definition at line 25 of file perftest_deleg_bydelegclient.cpp.

unsigned long totalRequests

Definition at line 29 of file perftest_deleg_bydelegclient.cpp.

Glib::TimeVal totalTime

Definition at line 32 of file perftest_deleg_bydelegclient.cpp.

std::string url_str

Definition at line 33 of file perftest_deleg_bydelegclient.cpp.