ect_throughput.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 730 行 · 第 1/2 页
CPP
730 行
// ECT_Throughput.cpp,v 1.46 2003/11/04 05:21:33 dhinton Exp
#include "ECT_Throughput.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/Event_Service_Constants.h"
#include "orbsvcs/Scheduler_Factory.h"
#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Sched/Config_Scheduler.h"
#include "orbsvcs/Runtime_Scheduler.h"
#include "orbsvcs/Event/Event_Channel.h"
#include "orbsvcs/Event/Module_Factory.h"
#include "orbsvcs/Event/EC_Event_Channel.h"
#include "orbsvcs/Event/EC_Default_Factory.h"
#include "tao/Timeprobe.h"
#include "tao/debug.h"
#include "ace/Get_Opt.h"
#include "ace/Auto_Ptr.h"
#include "ace/Sched_Params.h"
#include "ace/High_Res_Timer.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_errno.h"
ACE_RCSID(EC_Throughput, ECT_Throughput, "ECT_Throughput.cpp,v 1.46 2003/11/04 05:21:33 dhinton Exp")
int
main (int argc, char *argv [])
{
TAO_EC_Default_Factory::init_svcs ();
ECT_Throughput driver;
return driver.run (argc, argv);
}
// ****************************************************************
ECT_Throughput::ECT_Throughput (void)
: n_consumers_ (1),
n_suppliers_ (1),
burst_count_ (10),
burst_size_ (100),
event_size_ (128),
burst_pause_ (100),
consumer_type_start_ (ACE_ES_EVENT_UNDEFINED),
consumer_type_count_ (1),
consumer_type_shift_ (0),
supplier_type_start_ (ACE_ES_EVENT_UNDEFINED),
supplier_type_count_ (1),
supplier_type_shift_ (0),
pid_file_name_ (0),
active_count_ (0),
reactive_ec_ (0),
new_ec_ (1),
ec_concurrency_hwm_ (1),
thr_create_flags_ (THR_NEW_LWP|THR_BOUND|THR_SCHED_FIFO)
{
}
ECT_Throughput::~ECT_Throughput (void)
{
}
int
ECT_Throughput::run (int argc, char* argv[])
{
ACE_TRY_NEW_ENV
{
// Calibrate the high resolution timer *before* starting the
// test.
ACE_High_Res_Timer::calibrate ();
this->orb_ =
CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::Object_var poa_object =
this->orb_->resolve_initial_references("RootPOA"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
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_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
if (this->parse_args (argc, argv))
return 1;
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
"Execution parameters:\n"
" consumers = <%d>\n"
" suppliers = <%d>\n"
" burst count = <%d>\n"
" burst size = <%d>\n"
" event size = <%d>\n"
" burst pause = <%d>\n"
" consumer type start = <%d>\n"
" consumer type count = <%d>\n"
" consumer type shift = <%d>\n"
" supplier type start = <%d>\n"
" supplier type count = <%d>\n"
" supplier type shift = <%d>\n"
" pid file name = <%s>\n"
" reactive EC = <%d>\n"
" new EC = <%d>\n"
" concurrency HWM = <%d>\n",
this->n_consumers_,
this->n_suppliers_,
this->burst_count_,
this->burst_size_,
this->event_size_,
this->burst_pause_,
this->consumer_type_start_,
this->consumer_type_count_,
this->consumer_type_shift_,
this->supplier_type_start_,
this->supplier_type_count_,
this->supplier_type_shift_,
this->pid_file_name_?this->pid_file_name_:"nil",
this->reactive_ec_,
this->new_ec_,
this->ec_concurrency_hwm_
) );
}
if (this->pid_file_name_ != 0)
{
FILE* pid = ACE_OS::fopen (this->pid_file_name_, "w");
if (pid != 0)
{
ACE_OS::fprintf (pid, "%ld\n",
ACE_static_cast (long, ACE_OS::getpid ()));
ACE_OS::fclose (pid);
}
}
int priority =
(ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
+ ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
priority);
// Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
priority,
ACE_SCOPE_PROCESS)) != 0)
{
if (ACE_OS::last_error () == EPERM)
{
ACE_DEBUG ((LM_DEBUG,
"%s: user is not superuser, "
"so remain in time-sharing class\n", argv[0]));
this->thr_create_flags_ = THR_NEW_LWP;
}
else
ACE_ERROR ((LM_ERROR,
"%s: ACE_OS::sched_params failed\n", argv[0]));
}
if (ACE_OS::thr_setprio (priority) == -1)
{
ACE_ERROR ((LM_ERROR, "(%P|%t) main thr_setprio failed,"
"no real-time features\n"));
}
#if 1
ACE_Config_Scheduler scheduler_impl;
#else
#include "ECT_Scheduler_Info.h"
ACE_Runtime_Scheduler scheduler_impl (
runtime_configs_size,
runtime_configs,
runtime_infos_size,
runtime_infos);
#endif
RtecScheduler::Scheduler_var scheduler =
scheduler_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
#if 0
CORBA::Object_var naming_obj =
this->orb_->resolve_initial_references ("NameService"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (naming_obj.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to get the Naming Service.\n"),
1);
CosNaming::NamingContext_var naming_context =
CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// This is the name we (potentially) register the Scheduling
// Service in the Naming Service.
CosNaming::Name schedule_name (1);
schedule_name.length (1);
schedule_name[0].id = CORBA::string_dup ("ScheduleService");
CORBA::String_var str =
this->orb_->object_to_string (scheduler.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "The (local) scheduler IOR is <%s>\n",
str.in ()));
// Register the servant with the Naming Context....
naming_context->rebind (schedule_name, scheduler.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_Scheduler_Factory::use_config (naming_context.in ());
#endif /* 0 */
// The factories must be destroyed *after* the EC, hence the
// auto_ptr declarations must go first....
auto_ptr<TAO_Module_Factory> module_factory;
auto_ptr<POA_RtecEventChannelAdmin::EventChannel> ec_impl;
if (this->new_ec_ == 0)
{
if (this->reactive_ec_ == 1)
{
auto_ptr<TAO_Module_Factory> auto_module_factory (new TAO_Reactive_Module_Factory);
module_factory = auto_module_factory;
}
else
{
auto_ptr<TAO_Module_Factory> auto_module_factory (new TAO_Default_Module_Factory);
module_factory = auto_module_factory;
}
// Create the EC
auto_ptr<POA_RtecEventChannelAdmin::EventChannel> auto_ec_impl
(new ACE_EventChannel (scheduler.in (),
1,
ACE_DEFAULT_EVENT_CHANNEL_TYPE,
module_factory.get ()));
ec_impl = auto_ec_impl;
}
else
{
TAO_EC_Event_Channel_Attributes attr (root_poa.in (),
root_poa.in ());
TAO_EC_Event_Channel *ec =
new TAO_EC_Event_Channel (attr);
ec->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
auto_ptr<POA_RtecEventChannelAdmin::EventChannel> auto_ec_impl (ec);
ec_impl = auto_ec_impl;
}
RtecEventChannelAdmin::EventChannel_var channel =
ec_impl->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
this->connect_consumers (scheduler.in (),
channel.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "connected consumer(s)\n"));
this->connect_suppliers (scheduler.in (),
channel.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "connected supplier(s)\n"));
this->activate_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "suppliers are active\n"));
// Wait for the supplier threads...
if (ACE_Thread_Manager::instance ()->wait () == -1)
{
ACE_ERROR ((LM_ERROR, "Thread_Manager wait failed\n"));
return 1;
}
ACE_DEBUG ((LM_DEBUG, "suppliers finished\n"));
this->dump_results ();
this->disconnect_consumers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "consumers disconnected\n"));
this->disconnect_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "suppliers disconnected\n"));
channel->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "channel destroyed\n"));
{
// Deactivate the EC
PortableServer::POA_var poa =
ec_impl->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::ObjectId_var id =
poa->servant_to_id (ec_impl.get () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "EC deactivated\n"));
}
{
// Deactivate the Scheduler
PortableServer::POA_var poa =
scheduler_impl._default_POA (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::ObjectId_var id =
poa->servant_to_id (&scheduler_impl ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "scheduler deactivated\n"));
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"ECT_Throughput::run");
}
ACE_CATCHALL
{
ACE_ERROR ((LM_ERROR, "non-corba exception raised\n"));
}
ACE_ENDTRY;
return 0;
}
void
ECT_Throughput::shutdown_consumer (void*
ACE_ENV_ARG_DECL_NOT_USED)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?