[users@httpd] apache slower than IIS (testprogram)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hello,


the attached program shows a performance problem with apache2-worker.

compile with:

g++ curltest.cpp -lcurl

then start it with something like this:

./a.out -u http://ms.iss-server/a.jpg
./a.out -u http://apache2.server/a.jpg

With apache you get timeouts and the script takes 10 seconds (3.6 KB file).
IIS needs only 0.5 seconds.

any ideas?

Im using apache2-worker-2.0.53-9 suse 9.3 rpm.


regards,

Martin


/**
   compile with:

   g++ curltest.cpp -lcurl
 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <curl/curl.h>
#include <iostream>


static int bytecounter;
static int still_running;
static int removed=0;

using namespace std;

void usage() {
  printf("dbaccesstest is frontend for testing libdbaccess\n");
  printf("Usage : dbaccesstest [-u username] [-p password] [-s server]  [-h]\n\n");

  printf("-u : url to fetch\n");
  printf("-h : this message\n\n");

  printf("THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!\n\n");
  printf("example:\n");
  printf("./curltest -u http://media2.cluster/ \n");
  
}

#define TRANSFER_SIZE 16384
extern "C" size_t dev_null(void *ptr,size_t size,size_t nmemb,void *stream) {
  char buf[TRANSFER_SIZE];
  int back=TRANSFER_SIZE;
  int bytes=size*nmemb;
  if (bytes > TRANSFER_SIZE) bytes=TRANSFER_SIZE;
  memcpy(buf,ptr,bytes);
  bytecounter+=bytes;
  cout << "bytecounter:"<<bytecounter<<" still:"<<still_running<<endl;
  return bytes;
}


int remove_eof_handles(CURLM *multi_handle) {
  
  CURLMsg* curlmsg;
  int msgs_in_queue=0;
  curlmsg=curl_multi_info_read(multi_handle,&msgs_in_queue);
  if (curlmsg != NULL) {
    if (curlmsg->msg == CURLMSG_DONE) {
      CURLcode status;
      long val;
      status=curl_easy_getinfo(curlmsg->easy_handle,
			       CURLINFO_HTTP_CODE,&val);
      if (status == CURLE_OK) {
	cout << "response:"<<val<<endl;
      }	else {
	cout << "eroor curl ok"<<endl;
      }
      curl_multi_remove_handle(multi_handle,curlmsg->easy_handle);
      curl_easy_cleanup(curlmsg->easy_handle);
      removed++;
      cout << "removed:"<<removed<<endl;
    }
  }
  return msgs_in_queue;
}

int main(int argc, char **argv) {
  
  int c;
  
  char* url=NULL;
  bytecounter=0;

  
  while(1) {
    c = getopt (argc, argv, "u:h");
    if (c == -1) break;
    switch(c) {
    case 'u': {
      url=strdup(optarg);
      break;
    }
    case 'h': {
      usage(); 
      exit(0); 
    }
   default:
      printf ("?? getopt returned character code 0%o ??\n", c);
      usage();
      exit(-1);
    }
  }  

  if ( (url == NULL) ) {
    usage();
    exit(-1);
  }

  CURLcode res;
  CURLM *multi_handle;
  curl_global_init( CURL_GLOBAL_ALL ) ;

  multi_handle = curl_multi_init();
  if (multi_handle == NULL) {
    cout << "error setting up curl"<<endl;
    exit(-1);
  }
  int n=1000;
  int i;
  for(i=0;i<n;i++) {
    CURL* ctx = curl_easy_init() ;
    curl_easy_setopt(ctx, CURLOPT_URL, url);
    curl_easy_setopt(ctx, CURLOPT_WRITEFUNCTION, dev_null);
    curl_multi_add_handle(multi_handle, ctx);
  }

  while(CURLM_CALL_MULTI_PERFORM ==
	curl_multi_perform(multi_handle, &still_running));
  cout << "next iteration:"<<still_running<<endl;

  //exit(0);
  
  while(still_running) {
    struct timeval timeout;
    int rc; /* select() return code */
    //timeline_t timeline;
    //TimeWrapper::gettimeofday(&timeline.start_time);
    fd_set fdread;
    fd_set fdwrite;
    fd_set fdexcep;
    int maxfd;
    
    FD_ZERO(&fdread);
    FD_ZERO(&fdwrite);
    FD_ZERO(&fdexcep);
    
    /* set a suitable timeout to play around with */
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    
    /* get file descriptors from the transfers */
    curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
    //TimeWrapper::gettimeofday(&timeline.end_time);
    //TimeWrapper::substract(&timeline);
    //TimeWrapper::print(&timeline);

    rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);

    switch(rc) {
    case -1:
      /* select error */
      printf("select error\n");
      break;
    case 0:
      printf("timeout!\n");
    default:
      /* timeout or readable/writable sockets */
      while(CURLM_CALL_MULTI_PERFORM ==
	    curl_multi_perform(multi_handle, &still_running)) {

      }
      int doit=1;
      while(doit) {
	doit=remove_eof_handles(multi_handle);
      }
      break;
    }
  }
  curl_multi_cleanup(multi_handle);

  exit(0);
}





---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux