diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-03-25 07:04:06 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-03-25 07:04:06 +0000 |
commit | e818b5b0f0d53f97d2c006934710be4865d35b79 (patch) | |
tree | ebdb03060117ccd2beb5e590c655050fadb957df | |
parent | bfed9c6fbaa5dd86d903da056b3f5eb75f617354 (diff) | |
download | ATCD-e818b5b0f0d53f97d2c006934710be4865d35b79.tar.gz |
Initial (non-working) draft of TAO's new Load Balancer
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Hash_Replica.idl | 12 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.cpp | 52 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.h | 35 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.cpp | 65 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.h | 63 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/Makefile | 52 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/client.cpp | 13 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/LoadBalancing/server.cpp | 78 |
8 files changed, 370 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica.idl b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica.idl new file mode 100644 index 00000000000..11a2948a567 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica.idl @@ -0,0 +1,12 @@ +// -*- C++ -*- +// $Id$ + +interface Hash_Replica +{ + // = DESCRIPTION + // This Replica interface provides a simple hashing function. + + unsigned long do_hash (in string str, out string hashed_str); + // Perform a simple hashing operation on the input string <str> and + // return the hashed string <hash_str>. +}; diff --git a/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.cpp b/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.cpp new file mode 100644 index 00000000000..1df0e96b14d --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.cpp @@ -0,0 +1,52 @@ +// -*- C++ -*- + +// $Id$ + + +#include "Hash_ReplicaControl.h" + +Hash_ReplicaControl::Hash_ReplicaControl ( + LoadBalancing::LoadBalancer_ptr balancer) + : balancer_ (balancer), + replica_ (balancer->group_identity ()) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + LoadBalancing::ReplicaControl_var control = + this->_this (ACE_TRY_ENV); + ACE_TRY_CHECK; + + CORBA::Object_var replica = this->replica_._this (ACE_TRY_ENV); + ACE_TRY_CHECK; + + this->replica.balancer_proxy ( + this->balancer_->connect (control, + replica, + ACE_TRY_ENV)); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "LoadBalancer::connect"); + } + ACE_END_TRY; +} + +void +Hash_ReplicaControl::high_load_advisory (CORBA::Environment & + /* ACE_TRY_ENV */) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Notify the replica that it should reject all requests. + this->replica_.reject_requests (1); +} + +void +Hash_ReplicaControl::nominal_load_advisory (CORBA::Environment & + /* ACE_TRY_ENV */) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Notify the replica that it should once again accept requests. + this->replica_.reject_requests (0); +} diff --git a/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.h b/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.h new file mode 100644 index 00000000000..c31174be1b3 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Hash_ReplicaControl.h @@ -0,0 +1,35 @@ +// -*- C++ -*- + +// $Id$ + +#include "orbsvcs/LoadBalancingS.h" + +#ifndef TAO_HASH_REPLICACONTROL_H +#define TAO_HASH_REPLICACONTROL_H + +class Hash_ReplicaControl : public virtual POA_LoadBalancing::ReplicaControl +{ +public: + Hash_ReplicaControl (LoadBalancing::LoadBalancer_ptr balancer); + // Constructor. + + virtual void high_load_advisory (CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void nominal_load_advisory (CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)); + + CORBA::Object_ptr replica (void); + // Return a reference to the replica being load balanced. + +private: + LoadBalancing::LoadBalancer_var balancer_; + // Object reference to the load balancer. + + Hash_Replica_Impl replica_; + // Replica being load balanced. + + +}; + +#endif /* TAO_HASH_REPLICACONTROL_H */ diff --git a/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.cpp b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.cpp new file mode 100644 index 00000000000..229542fd47b --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.cpp @@ -0,0 +1,65 @@ +// -*- C++ -*- +// $Id$ + +#include "ace/ACE.h" + +#include "Hash_Replica_i.h" + + +Hash_Replica_Impl::Hash_Replica_Impl (CORBA::Object_ptr load_balanced_group) + : load_balanced_group_ (load_balanced_group), + reject_requests_ (0), + requests_ (0), + start_ (0, 0) +{ + // Nothing else +} + +CORBA::ULong Replica_Impl::do_hash (const char *str, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableServer::ForwardRequest)) +{ + if (this->reject_requests_) + ACE_THROW_RETURN (PortableServer::ForwardRequest ( + CORBA::Object::_duplicate ( + this->load_balanced_group_.in ())), + 0); + + // Update the load (requests per second) + + if (this->start_ == 0) + this->start_ = ACE_OS::gettimeofday (); + + ACE_Time_Value elapsed_time = + ACE_OS::gettimeofday () - this->start_; + + this->requests_++; + CORBA::Float load = this->requests_ / elapsed_time.sec (); + + this->balancer_proxy_->current_load (load, + ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + + // If 20 seconds have elapsed, then reset the load measurements. + if (elapsed_time.sec () >= 20) + { + this->start_ = ACE_OS::gettimeofday (); + this->requests_ = 0; + } + + // Return the hash. + return ACE::hash_pjw (str); +} + +void +Hash_Replica_Impl::balancer_proxy (LoadBalancing::ReplicaProxy_ptr proxy) +{ + this->balancer_proxy_ = proxy; +} + +void +Hash_Replica_Impl::reject_requests (int reject) +{ + this->reject_requests_ = reject; +} diff --git a/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.h b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.h new file mode 100644 index 00000000000..f7a876a2018 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Hash_Replica_i.h @@ -0,0 +1,63 @@ +// -*- C++ -*- +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// orbsvcs/tests/LoadBalancing +// +// = FILENAME +// Hash_Replica_i.h +// +// = AUTHOR +// Ossama Othman <ossama@uci.edu> +// +// ============================================================================ + +#include "orbsvcs/LoadBalancingS.h" + +#include "Hash_ReplicaS.h" + +#ifndef TAO_HASH_REPLICA_I_H +#define TAO_HASH_REPLICA_I_H + + +class Hash_Replica_Impl : public virtual POA_Hash_Replica +{ +public: + Hash_Replica_Impl (CORBA::Object_ptr load_balanced_group); + // Constructor + + virtual CORBA::ULong do_hash (const char * str, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableServer::ForwardRequest)); + // Perform a simple hashing operation on the input string <str> and + // return the hashed string <hash_str>. + + void reject_requests (int reject); + // Inform the Replica that it should or should not accept client + // requests. 0 == accept requests, ~0 == reject requests + +private: + CORBA::Object_var load_balanced_group_; + // Reference that represents the collective identity of replicas + // being load balanced. + + LoadBalancing::ReplicaProxy_var balancer_proxy_; + // Object reference to the load balancer proxy. + + int reject_requests_; + // Flag that indicates whether the servant should reject all client + // requests. + + CORBA::ULong requests_; + // The number of requests since load measurements started. + + ACE_Time_Value start_; + // Time when load measurements started. +}; + + +#endif /* TAO_HASH_REPLICA_I_H */ + diff --git a/TAO/orbsvcs/tests/LoadBalancing/Makefile b/TAO/orbsvcs/tests/LoadBalancing/Makefile new file mode 100644 index 00000000000..0ff797cfb43 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/Makefile @@ -0,0 +1,52 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif # ! TAO_ROOT + +LDLIBS = -lTAO + +IDLFILES = Hash_ReplicaC Hash_ReplicaS +BIN = client server + +SRC = $(addsuffix .cpp, $(BIN) $(IDLFILES)) + +CLIENT_OBJS = client.o $(addsuffix .o, $(IDLFILES)) +SERVER_OBJS = server.o test_i.o $(addsuffix .o, $(IDLFILES)) + +TAO_IDLFLAGS += -Ge 1 +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(TAO_ROOT)/rules.tao.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU +include $(TAO_ROOT)/taoconfig.mk + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +.PRECIOUS: $(foreach ext, $(IDL_EXT), test$(ext)) + +server: $(addprefix $(VDIR),$(SERVER_OBJS)) + $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK) + +client: $(addprefix $(VDIR),$(CLIENT_OBJS)) + $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK) + +realclean: clean + -$(RM) $(foreach ext, $(IDL_EXT), test$(ext)) + diff --git a/TAO/orbsvcs/tests/LoadBalancing/client.cpp b/TAO/orbsvcs/tests/LoadBalancing/client.cpp new file mode 100644 index 00000000000..2855b63ef6e --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/client.cpp @@ -0,0 +1,13 @@ +// -*- C++ -*- + +// $Id$ + +// TAO Load Balancer test client + +int +main (int argc, char *argv[]) +{ + + + return 0; +} diff --git a/TAO/orbsvcs/tests/LoadBalancing/server.cpp b/TAO/orbsvcs/tests/LoadBalancing/server.cpp new file mode 100644 index 00000000000..1c1740ff18d --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/server.cpp @@ -0,0 +1,78 @@ +// -*- C++ -*- + +// $Id$ + +#include "ace/Get_Opt.h" + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + // Initialize ORB. + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "", ACE_TRY_ENV); + ACE_TRY_CHECK; + + CORBA::String_var balancer_ior; + + // Parse the application options after the ORB has been + // initialized. + ACE_Get_Opt options (argc, argv, "k:"); + int c = 0; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + IOR = CORBA::string_dup (options.optarg); + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s -k <Load Balancer IOR>\n", + argv[0]), + -1); + } + + CORBA::Object_var poa_object = + orb->resolve_initial_references ("RootPOA"); + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + 1); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in (), ACE_TRY_ENV); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_TRY_ENV); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_TRY_ENV); + ACE_TRY_CHECK; + + CORBA::Object_ptr load_balancer = + orb->string_to_object (balancer_ior.in ()); + + Hash_ReplicaControl control (load_balancer); + + orb->run (ACE_TRY_ENV); + ACE_TRY_CHECK; + + orb->shutdown (ACE_TRY_ENV); + ACE_TRY_CHECK; + + orb->destroy (ACE_TRY_ENV); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "SYS_EX"); + } + ACE_ENDTRY; + + + return 0; +} |