Skip to content

Commit 3ae0df3

Browse files
authored
Merge pull request #2525 from jwillemsen/jwi-transportidle
[ace6tao2] Backport #2523, add `-ORBTransportIdleTimeout` to purge idle transports
2 parents 98e5a3f + c836e5c commit 3ae0df3

30 files changed

Lines changed: 1539 additions & 80 deletions

ACE/ace/Event_Handler_Handle_Timeout_Upcall.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ timeout (ACE_Timer_Queue &timer_queue,
2929
int recurring_timer,
3030
const ACE_Time_Value &cur_time)
3131
{
32-
int requires_reference_counting = 0;
32+
bool requires_reference_counting = false;
3333

3434
if (!recurring_timer)
3535
{
@@ -47,8 +47,7 @@ timeout (ACE_Timer_Queue &timer_queue,
4747
timer_queue.cancel (event_handler, 0); // 0 means "call handle_close()".
4848
}
4949

50-
if (!recurring_timer &&
51-
requires_reference_counting)
50+
if (!recurring_timer && requires_reference_counting)
5251
{
5352
event_handler->remove_reference ();
5453
}

ACE/ace/WFMO_Reactor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ ACE_WFMO_Reactor_Handler_Repository::make_changes_in_suspension_infos (void)
870870
// the upcall.
871871
if (event_handler != 0)
872872
{
873-
int requires_reference_counting =
873+
bool const requires_reference_counting =
874874
event_handler->reference_counting_policy ().value () ==
875875
ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
876876

@@ -2062,7 +2062,7 @@ ACE_WFMO_Reactor::simple_dispatch_handler (DWORD slot,
20622062
ACE_Event_Handler *event_handler =
20632063
this->handler_rep_.current_info ()[slot].event_handler_;
20642064

2065-
int requires_reference_counting =
2065+
bool const requires_reference_counting =
20662066
event_handler->reference_counting_policy ().value () ==
20672067
ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
20682068

TAO/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
USER VISIBLE CHANGES BETWEEN TAO-2.5.23 and TAO-2.5.24
22
======================================================
33

4+
. All issues from bugzilla.dre.vanderbilt.edu migrated to
5+
https://github.com/DOCGroup/bugzilla
6+
7+
. Add -ORBTransportIdleTimeout to purge idle transports after
8+
a configurable timeout, default is 0 (no purging of idle transports)
9+
410
USER VISIBLE CHANGES BETWEEN TAO-2.5.22 and TAO-2.5.23
511
======================================================
612

TAO/bin/tao_orb_tests.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ TAO/tests/TransportCurrent/Framework/run_test.pl -static: !DISABLE_TRANSPORT_CUR
428428
TAO/tests/TransportCurrent/IIOP/run_test.pl -dynamic: !DISABLE_TRANSPORT_CURRENT !STATIC !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !MINIMUM
429429
TAO/tests/TransportCurrent/IIOP/run_test.pl -static: !DISABLE_TRANSPORT_CURRENT STATIC !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !MINIMUM
430430
TAO/tests/Transport_Cache_Manager/run_test.pl
431+
TAO/tests/Transport_Idle_Timeout/run_test.pl
431432
TAO/tests/UNKNOWN_Exception/run_test.pl:
432433
TAO/tests/Native_Exceptions/run_test.pl:
433434
TAO/tests/Servant_To_Reference_Test/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !ST

TAO/docs/Options.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,12 @@ <h4><a name="TDRF">1.1. Resource_Factory</a></h4>
13891389
to your config.h file.
13901390
</td>
13911391
</tr>
1392+
<tr>
1393+
<td><code>-ORBTransportIdleTimeout</code> <em>number</em></td>
1394+
<td>Number of seconds after which idle connections are closed and purged from
1395+
the transport cache. By default idle connections are kept until they are
1396+
explicitly closed or purged because the transport cache is almost full.</td>
1397+
</tr>
13921398
</tbody>
13931399
</table>
13941400
</p>

TAO/tao/Cache_Entries_T.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ namespace TAO
112112
is_delete_ (false),
113113
index_ (0)
114114
{
115-
116115
}
117116

118117
template <typename TRANSPORT_DESCRIPTOR_TYPE> ACE_INLINE

TAO/tao/Resource_Factory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ class TAO_Export TAO_Resource_Factory : public ACE_Service_Object
255255
/// replies during shutdown.
256256
virtual bool drop_replies_during_shutdown () const = 0;
257257

258+
/// Amount of seconds after which an idle transport will be closed
259+
/// 0 means no closing of idle connections (default)
260+
virtual int transport_idle_timeout () const = 0;
261+
258262
protected:
259263
/**
260264
* Loads the default protocols. This method is used so that the

TAO/tao/Transport.cpp

Lines changed: 119 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ TAO_Transport::TAO_Transport (CORBA::ULong tag,
134134
, incoming_message_queue_ (orb_core)
135135
, current_deadline_ (ACE_Time_Value::zero)
136136
, flush_timer_id_ (-1)
137+
, idle_timer_id_ (-1)
137138
, transport_timer_ (this)
139+
, transport_idle_timer_ (this)
138140
, handler_lock_ (orb_core->resource_factory ()->create_cached_connection_lock ())
139141
, id_ ((size_t) this)
140142
, purging_order_ (0)
@@ -202,6 +204,8 @@ TAO_Transport::~TAO_Transport (void)
202204
));
203205
}
204206

207+
this->cancel_idle_timer ();
208+
205209
delete this->messaging_object_;
206210

207211
delete this->ws_;
@@ -359,6 +363,16 @@ TAO_Transport::register_if_necessary (void)
359363
void
360364
TAO_Transport::close_connection (void)
361365
{
366+
if (TAO_debug_level > 4)
367+
{
368+
TAOLIB_DEBUG ((LM_DEBUG,
369+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::close_connection\n"),
370+
this->id ()));
371+
}
372+
373+
// Cancel any pending timer
374+
this->cancel_idle_timer ();
375+
362376
this->connection_handler_i ()->close_connection ();
363377
}
364378

@@ -410,8 +424,7 @@ TAO_Transport::register_handler (void)
410424
this->ws_->is_registered (true);
411425

412426
// Register the handler with the reactor
413-
return r->register_handler (this->event_handler_i (),
414-
ACE_Event_Handler::READ_MASK);
427+
return r->register_handler (this->event_handler_i (), ACE_Event_Handler::READ_MASK);
415428
}
416429

417430
int
@@ -582,7 +595,12 @@ TAO_Transport::make_idle (void)
582595
this->id ()));
583596
}
584597

585-
return this->transport_cache_manager ().make_idle (this->cache_map_entry_);
598+
int const result = this->transport_cache_manager ().make_idle (this->cache_map_entry_);
599+
if (result == 0)
600+
{
601+
this->schedule_idle_timer ();
602+
}
603+
return result;
586604
}
587605

588606
int
@@ -992,6 +1010,46 @@ TAO_Transport::handle_timeout (const ACE_Time_Value & /* current_time */,
9921010
return 0;
9931011
}
9941012

1013+
int
1014+
TAO_Transport::handle_idle_timeout (const ACE_Time_Value & /* current_time */, const void */*act*/)
1015+
{
1016+
if (TAO_debug_level > 6)
1017+
{
1018+
TAOLIB_DEBUG ((LM_DEBUG,
1019+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::handle_idle_timeout, ")
1020+
ACE_TEXT ("idle timer expired, closing transport\n"),
1021+
this->id ()));
1022+
}
1023+
1024+
// Timer has expired, so setting the idle timer id back to -1
1025+
this->idle_timer_id_ = -1;
1026+
1027+
if (this->transport_cache_manager ().purge_entry_when_purgable (this->cache_map_entry_) == -1)
1028+
{
1029+
if (TAO_debug_level > 6)
1030+
TAOLIB_DEBUG ((LM_DEBUG,
1031+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::handle_idle_timeout, ")
1032+
ACE_TEXT ("idle_timeout, transport is not purgable, don't close it, reschedule it\n"),
1033+
this->id ()));
1034+
1035+
this->schedule_idle_timer ();
1036+
}
1037+
else
1038+
{
1039+
if (TAO_debug_level > 6)
1040+
TAOLIB_DEBUG ((LM_DEBUG,
1041+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::handle_idle_timeout, ")
1042+
ACE_TEXT ("idle_timeout, transport purged due to idle timeout\n"),
1043+
this->id ()));
1044+
1045+
// Close the underlying socket.
1046+
// close_connection() is safe to call from the reactor thread.
1047+
(void) this->close_connection ();
1048+
}
1049+
1050+
return 0;
1051+
}
1052+
9951053
TAO_Transport::Drain_Result
9961054
TAO_Transport::drain_queue (TAO::Transport::Drain_Constraints const & dc)
9971055
{
@@ -2767,8 +2825,7 @@ TAO_Transport::pre_close (void)
27672825
// of the is_connected_ flag, so that during cache lookups the cache
27682826
// manager doesn't need to be burdened by the lock in is_connected().
27692827
this->is_connected_ = false;
2770-
this->transport_cache_manager ().mark_connected (this->cache_map_entry_,
2771-
false);
2828+
this->transport_cache_manager ().mark_connected (this->cache_map_entry_, false);
27722829
this->purge_entry ();
27732830
{
27742831
ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->handler_lock_));
@@ -2842,13 +2899,13 @@ TAO_Transport::post_open (size_t id)
28422899
ACE_TEXT (", cache_map_entry_ is [%@]\n"), this->id_, this->cache_map_entry_));
28432900
}
28442901

2845-
this->transport_cache_manager ().mark_connected (this->cache_map_entry_,
2846-
true);
2902+
this->transport_cache_manager ().mark_connected (this->cache_map_entry_, true);
28472903

28482904
// update transport cache to make this entry available
2849-
this->transport_cache_manager ().set_entry_state (
2850-
this->cache_map_entry_,
2851-
TAO::ENTRY_IDLE_AND_PURGABLE);
2905+
this->transport_cache_manager ().set_entry_state (this->cache_map_entry_, TAO::ENTRY_IDLE_AND_PURGABLE);
2906+
2907+
// this transport is just opened, so schedule it for the idle timer
2908+
this->schedule_idle_timer ();
28522909

28532910
return true;
28542911
}
@@ -2919,4 +2976,56 @@ TAO_Transport::connection_closed_on_read (void) const
29192976

29202977
//@@ TAO_TRANSPORT_SPL_METHODS_ADD_HOOK
29212978

2979+
void
2980+
TAO_Transport::schedule_idle_timer ()
2981+
{
2982+
int const timeout_sec = this->orb_core_->resource_factory ()->transport_idle_timeout ();
2983+
if (timeout_sec > 0)
2984+
{
2985+
if (this->idle_timer_id_ != -1)
2986+
{
2987+
// The transport was marked as idle, but we have a timer running, cancel that old timer
2988+
// first
2989+
this->cancel_idle_timer ();
2990+
}
2991+
ACE_Reactor *reactor = this->orb_core_->reactor ();
2992+
if (reactor)
2993+
{
2994+
ACE_Time_Value const tv (static_cast<time_t> (timeout_sec));
2995+
this->idle_timer_id_= reactor->schedule_timer (&this->transport_idle_timer_, 0, tv);
2996+
2997+
if (TAO_debug_level > 6)
2998+
{
2999+
TAOLIB_DEBUG ((LM_DEBUG,
3000+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::schedule_idle_timer, ")
3001+
ACE_TEXT ("schedule idle timer with id [%d] ")
3002+
ACE_TEXT ("in the reactor.\n"),
3003+
this->id (), this->idle_timer_id_));
3004+
}
3005+
}
3006+
}
3007+
}
3008+
3009+
void
3010+
TAO_Transport::cancel_idle_timer ()
3011+
{
3012+
if (this->idle_timer_id_ != -1)
3013+
{
3014+
ACE_Reactor *reactor = this->orb_core ()->reactor ();
3015+
if (reactor)
3016+
{
3017+
if (TAO_debug_level > 6)
3018+
{
3019+
TAOLIB_DEBUG ((LM_DEBUG,
3020+
ACE_TEXT ("TAO (%P|%t) - Transport[%d]::cancel_idle_timer, ")
3021+
ACE_TEXT ("cancel idle timer with id [%d] ")
3022+
ACE_TEXT ("from the reactor.\n"),
3023+
this->id (), this->idle_timer_id_));
3024+
}
3025+
reactor->cancel_timer (this->idle_timer_id_);
3026+
this->idle_timer_id_ = -1;
3027+
}
3028+
}
3029+
}
3030+
29223031
TAO_END_VERSIONED_NAMESPACE_DECL

TAO/tao/Transport.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// -*- C++ -*-
2-
3-
//=============================================================================
41
/**
52
* @file Transport.h
63
*
@@ -9,7 +6,6 @@
96
*
107
* @author Fred Kuhns <fredk@cs.wustl.edu>
118
*/
12-
//=============================================================================
139

1410
#ifndef TAO_TRANSPORT_H
1511
#define TAO_TRANSPORT_H
@@ -23,6 +19,7 @@
2319
#endif /* ACE_LACKS_PRAGMA_ONCE */
2420

2521
#include "tao/Transport_Timer.h"
22+
#include "tao/Transport_Idle_Timer.h"
2623
#include "tao/Incoming_Message_Queue.h"
2724
#include "tao/Incoming_Message_Stack.h"
2825
#include "tao/Message_Semantics.h"
@@ -867,6 +864,9 @@ class TAO_Export TAO_Transport
867864
*/
868865
int handle_timeout (const ACE_Time_Value &current_time, const void* act);
869866

867+
/// Timeout called when the idle timer expired for this transport
868+
int handle_idle_timeout (const ACE_Time_Value &current_time, const void* act);
869+
870870
/// Accessor to recv_buffer_size_
871871
size_t recv_buffer_size (void) const;
872872

@@ -910,6 +910,9 @@ class TAO_Export TAO_Transport
910910
/// Transport statistics
911911
TAO::Transport::Stats* stats (void) const;
912912

913+
/// Helper method to cancel the timer when the transport is not idle anymore
914+
void cancel_idle_timer ();
915+
913916
private:
914917
/// Helper method that returns the Transport Cache Manager.
915918
TAO::Transport_Cache_Manager &transport_cache_manager (void);
@@ -1072,10 +1075,8 @@ class TAO_Export TAO_Transport
10721075
*/
10731076
bool using_blocking_io_for_asynch_messages() const;
10741077

1075-
/*
1076-
* Specialization hook to add concrete private methods from
1077-
* TAO's protocol implementation onto the base Transport class
1078-
*/
1078+
/// Helper method to schedule a timer when the transport is made idle
1079+
void schedule_idle_timer ();
10791080

10801081
//@@ TAO_TRANSPORT_SPL_PRIVATE_METHODS_ADD_HOOK
10811082

@@ -1138,8 +1139,14 @@ class TAO_Export TAO_Transport
11381139
/// The timer ID
11391140
long flush_timer_id_;
11401141

1142+
/// The idle timer ID
1143+
long idle_timer_id_;
1144+
11411145
/// The adapter used to receive timeout callbacks from the Reactor
1142-
TAO_Transport_Timer transport_timer_;
1146+
TAO::Transport_Timer transport_timer_;
1147+
1148+
/// The adapter used to receive idle timeout callbacks from the Reactor
1149+
TAO::Transport_Idle_Timer transport_idle_timer_;
11431150

11441151
/// Lock that insures that activities that *might* use handler-related
11451152
/// resources (such as a connection handler) get serialized.

0 commit comments

Comments
 (0)