[omniORB] Re:Connection management

Jorge Garcia soft@mabyc.com
Wed, 26 Jan 2000 15:05:46 +0100


****
****  Sai-Lai Lo wrote:

  omniORB::maxTcpConnectionPerServer controls on the client side how
many
  concurrent request the client will invoke on the server. If the number
of
  request to the same server is more than this number, the other
requests
  will be queued until the previous ones return.

  If you want more concurrent requests, set the variable to a higher
number
  before you call ORB_init.


****
****  Haarek Ryeng wrote:


  ORBinConScanPeriod = 180 sec. // should be less than call freq of your

                                                          // client
threads !!!

  ORBoutConScanPeriod = 120 sec.

  I think these are the ones you have to tune !

  The ORBscanGranularity is merely the sampling frequency and defines
the
  accurancy of the above timeout periods.

  More effectively,if you have threads and socket enouhg, boost your
  maxTcpConnectionPerServer.


****
*********

  Hi,

    Right, if I set omniORB::maxTcpConnectionPerServer = 10 all works
    fine, but, I want to have a limited number of server threads,
because
    I don't know how many threads will be spawned by my client.

    I have tried different parameter combinations and I have got the
next results:

    * using default values:

    - server: ./server.exe

          Thread 0 into remote function.
          Thread 1 into remote function.
          Thread 2 into remote function.
          Thread 3 into remote function.
          Thread 4 into remote function.
          Thread 0 out of remote funciton.
          Thread 1 out of remote funciton.
          Thread 2 out of remote funciton.
          Thread 3 out of remote funciton.
          Thread 4 out of remote funciton.
          Thread 5 into remote function.
          Thread 5 out of remote funciton.
          Thread 6 into remote function.
          Thread 6 out of remote funciton.
          Thread 7 into remote function.
          Thread 7 out of remote funciton.
          Thread 8 into remote function.
          Thread 8 out of remote funciton.
          Thread 9 into remote function.
          Thread 9 out of remote funciton.

    - client: ./client.exe 5

          Start...
          starting thread: 0
          starting thread: 1
          starting thread: 2
          starting thread: 3
          starting thread: 4
          starting thread: 5
          starting thread: 6
          starting thread: 7
          starting thread: 8
          starting thread: 9
          thread 0 finished in 20.02 sec.
          thread 1 finished in 20.021 sec.
          thread 2 finished in 20.023 sec.
          thread 3 finished in 20.039 sec.
          thread 4 finished in 20.042 sec.
          thread 5 finished in 40.032 sec.
          thread 6 finished in 60.006 sec.
          thread 7 finished in 80 sec.
          thread 8 finished in 99.991 sec.
          thread 9 finished in 119.982 sec.
          End...
          Time: 120.257


     * using these parameters:

         omniORB::scanGranularity(3);
         omniORB::idleConnectionScanPeriod(omniORB::idleIncoming,3);
         omniORB::idleConnectionScanPeriod(omniORB::idleOutgoing,3);
         omniORB::callTimeOutPeriod(omniORB::clientSide,20);
         omniORB::callTimeOutPeriod(omniORB::serverSide,3);

        - server: ./server.exe

          Thread 0 into remote function.
          Thread 1 into remote function.
          Thread 2 into remote function.
          Thread 3 into remote function.
          Thread 4 into remote function.
          Thread 0 out of remote funciton.
          Thread 1 out of remote funciton.
          Thread 2 out of remote funciton.
          Thread 3 out of remote funciton.
          Thread 4 out of remote funciton.
          Thread 5 into remote function.
          Thread 5 into remote function. ???????
          Thread 6 into remote function.
          Thread 7 into remote function.
          Thread 8 into remote function.
          Thread 9 into remote function.
          Thread 5 out of remote funciton.
          Thread 9 out of remote funciton.
          Thread 8 out of remote funciton.
          Thread 7 out of remote funciton.
          Thread 6 out of remote funciton.
          Thread 5 out of remote funciton. ??????

        - client: ./client.exe 5

          Start...
          starting thread: 0
          starting thread: 1
          starting thread: 2
          starting thread: 3
          starting thread: 4
          starting thread: 5
          starting thread: 6
          starting thread: 7
          starting thread: 8
          starting thread: 9
          thread 0 finished in 20.018 sec.
          thread 1 finished in 20.01 sec.
          thread 2 finished in 20.014 sec.
          thread 3 finished in 20.027 sec.
          thread 4 finished in 20.012 sec.
          thread 5 finished in 58.885 sec.
          thread 6 finished in 58.867 sec.
          thread 7 finished in 58.848 sec.
          thread 8 finished in 58.831 sec.
          thread 9 finished in 58.812 sec.
          End...
          Time: 59.04



  The results that I want to obtain are:

     - server:

          Thread 0 into remote function.
          Thread 1 into remote function.
          Thread 2 into remote function.
          Thread 3 into remote function.
          Thread 4 into remote function.
          Thread 0 out of remote funciton.
          Thread 1 out of remote funciton.
          Thread 2 out of remote funciton.
          Thread 3 out of remote funciton.
          Thread 4 out of remote funciton.
          Thread 5 into remote function.
          Thread 6 into remote function.
          Thread 7 into remote function.
          Thread 8 into remote function.
          Thread 9 into remote function.
          Thread 5 out of remote funciton.
          Thread 6 out of remote funciton.
          Thread 7 out of remote funciton.
          Thread 8 out of remote funciton.
          Thread 9 out of remote funciton.

     - client: ./client.exe 5

      Start...
      starting thread: 0
      starting thread: 1
      starting thread: 2
      starting thread: 3
      starting thread: 4
      starting thread: 5
      starting thread: 6
      starting thread: 7
      starting thread: 8
      starting thread: 9
      thread 0 finished in 20.018 sec.
      thread 1 finished in 20.01 sec.
      thread 2 finished in 20.014 sec.
      thread 3 finished in 20.027 sec.
      thread 4 finished in 20.012 sec.
      thread 5 finished in 40.xxx sec.
      thread 6 finished in 40.xxx sec.
      thread 7 finished in 40.xxx sec.
      thread 8 finished in 40.xxx sec.
      thread 9 finished in 40.xxx sec.
      End...
      Time: 40.xx

Regards,

Jorge Garcia
R&D Software Engineer
Mabyc, S.A.
Barcelona (Spain)

========
SOURCES
========

-------
libreria.idl
-------

#define __LIBRERIA_IDL__

module Libreria
{
 interface Funciones
 {
  long suma(in long value,in long tnum);
 };
};

#endif

--------
libreria_i.cc
--------

#include <iostream.h>
#include <unistd.h>
#include "libreria.hh"

class Libreria_i : public virtual Libreria::_sk_Funciones
{
 public:
  Libreria_i() {}
  virtual ~Libreria_i() {}
  virtual long suma(long value,long tnum);
};

long Libreria_i::suma(long value,long tnum)
{
 cout << "Thread " << tnum << " into remote function." << endl;
 sleep(20);
 value+=tnum;
 cout << "Thread " << tnum << " out of remote funciton. " << endl;
 return value;
}

-------
server.cc
-------

#include <iostream.h>
#include <fstream.h>
#include "omnithread.h"
#include "libreria.hh"
#include "libreria_i.cc"

int main(int argc, char **argv)
{
 try
 {
  CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB2");
  CORBA::BOA_ptr boa = orb->BOA_init(argc,argv,"omniORB2_BOA");

  Libreria_i *myobj = new Libreria_i();

  myobj->_obj_is_ready(boa);

  Libreria::Funciones_var myobjRef = myobj->_this();

  CORBA::String_var p = orb->object_to_string(myobjRef);

  ofstream out ("LIBRERIA.IOR");
  out << (char*)p << endl;
  out.close();

  boa->impl_is_ready();

  boa->destroy();
  orb->NP_destroy();
 }
 catch(...)
 {
  cout << "exception into server." << endl;
 }
 return 0;
}

------
client.cc
------

#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "libreria.hh"

#define MAXTHREADS 10

struct thread_info
{
 int pos;
 pthread_t id;
 int result;
 Libreria::Funciones_var e;
};

struct thread_info thread_list[MAXTHREADS];

long da_milis()
{
 struct timeval tv;
 gettimeofday(&tv,NULL);
 return (tv.tv_sec*1000L) + (tv.tv_usec/1000L);
}

void* ThreadFunction(void* p)
{
 long min,mout;
 double res;

 try
 {
  cout << "starting thread: " << (long)(*(long*)p) <<  endl;
  min=da_milis();
  thread_list[(long)(*(long*)p)].e->suma(1,(long)(*(long*)p));
  mout=da_milis();
  res=(double)((mout-min)/1000.0);
  cout << "thread " << (long)(*(long*)p) << " finished in " << res << "
sec." << endl;
 }
 catch(CORBA::COMM_FAILURE& ex)
 {
  cerr << "Caught system exception COMM_FAILURE, unable to contact the "

       << "object." << endl;
 }
 catch(...)
 {
  cout << "Eexception" << endl;
 }

 pthread_exit(p);
}

void main (int argc, char **argv)
{
 try
 {
  long min,mout,buc;
  double res;
  char ref[1000];
  int i;

  ifstream in("LIBRERIA.IOR");

  CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB2");
  CORBA::Object_ptr obj2;

  omniORB::maxTcpConnectionPerServer=atoi(argv[1]);
  //omniORB::scanGranularity(3);
  //omniORB::idleConnectionScanPeriod(omniORB::idleIncoming,3);
  //omniORB::idleConnectionScanPeriod(omniORB::idleOutgoing,3);
  //omniORB::callTimeOutPeriod(omniORB::clientSide,20);
  //omniORB::callTimeOutPeriod(omniORB::serverSide,3);

  in >> ref;
  in.close();

  CORBA::Object_var obj = orb->string_to_object(ref);
  obj2=obj;

  for(i=0;i<MAXTHREADS;i++)
  {
   thread_list[i].e = Libreria::Funciones::_narrow(obj2);
   thread_list[i].pos = i;
   if (CORBA::is_nil(thread_list[i].e))
   {
     cerr << "hello: cannot invoke on a nil object reference.\n" <<
endl;
     return;
   }
  }

  cout << "Start..." << endl;

  min=da_milis();

  for(i=0;i<MAXTHREADS;i++)
  {

pthread_create(&thread_list[i].id,NULL,&ThreadFunction,&thread_list[i].pos);

  }

  for(i=0;i<MAXTHREADS;i++)
  {
   pthread_join(thread_list[i].id,(void*)&thread_list[i].result);
  }

  mout=da_milis();

  res=(double)((mout-min)/1000.0);

  cout << "End..." << endl;

  cout << "Time: " << res << endl;

  orb->NP_destroy();
 }
catch(CORBA::COMM_FAILURE& ex)
 {
  cerr << "Caught system exception COMM_FAILURE, unable to contact the "

       << "object." << endl;
 }
 catch(omniORB::fatalException& ex)
 {
  cerr << "Caught omniORB2 fatalException. This indicates a bug is
caught "
       << "within omniORB2.\nPlease send a bug report.\n"
       << "The exception was thrown in file: " << ex.file() << "\n"
   << "                            line: " << ex.line() << "\n"
       << "The error message is: " << ex.errmsg() << endl;
 }
 catch(...)
 {
  cerr << "Caught a system exception." << endl;
 }

 return 0;
}