A thread, or a single sequential flow of control within a process, is also called a lightweight process that reduces overhead by sharing fundamental parts with other threads. Threads are lightweight so that there can be many of them present within a process.
The two major thread models supported by VisiBroker are the thread pool (also known as thread-per-request, or TPool) and thread-per-session (also known as thread-per-connection, or
TSession). Single-thread and main-thread models are not discussed in this document. The thread pool and thread-per-session models differ in these fundamental ways:
With the thread-per-session (TSession) policy, threading is driven by connections between the client and server processes. When your server selects the thread-per-session policy, a new thread is allocated each time a new client connects to a server. A thread is assigned to handle all the requests received from a particular client. Because of this, thread-per-session is also referred to as thread-per-connection. When the client disconnects from the server, the thread is destroyed. You may limit the maximum number of threads that can be allocated for client connections by setting the
vbroker.se.iiop_ts.scm.iiop_ts.manager.connectionMax property.
In the following scenario, a client application is bound to two objects in the server process. Each bind() shares a common connection to the server process, even though the
bind() is for a different object in the server process.
On the server side, a client's host and the port details are obtainable by the use of a PeerConnectionCurrent interface. The
PeerConnectionCurrent interface is defined as follows:
The reference to PeerConnectionCurrent interface is obtained by a call to org.omg.CORBA.ORB.resolve_initial_references("PeerConnectionCurrent"). If the client and server are colocated, a call to
getPeerHost will return the localhost address and
getPeerPort will return "
0" (zero).
The host address is returned as a dotted IP address string. The precondition for the use of PeerConnectionCurrent is that it can only be used from inside a request's invocation context. Outside the invocation context, a call to
getPeerHost and
getPeerPort raises a
BAD_INV_ORDER exception.
PeerConnectionCurrent can be called from inside in the following ways:
However, if the ServantLocator is being used, then the
PeerConnectionCurrent cannot be called from within the
ServerRequestInterceptor preinvoke or the
ServerRequestInterceptor receive_request_service_contexts and the
ServantLocator preinvoke methods. Otherwise, this will result with a
BAD_INV_ORDER exception.
The set of Server Connection Managers associated with a ServerEngine is defined by this property. The name specified in the above property as the <svr_eng_name> is the name of the ServerEngine. The SCMs listed here will be the list of SCMs for the associated server engine. SCMs cannot be shared between ServerEngines. However, ServerEngines can be shared by multiple POAs.
The host property is the IP address for the server engine to listen for messages.
The proxyHost property specifies the proxy IP address to send to the client in the case where the server does not want to publish its real hostname.
Each POA in a multi-threaded object server can choose between two dispatch models: thread-per-session or
thread pool. You choose a dispatch policy by setting the
dispatcher.type property of the
ServerEngine.
ThreadPool (thread pooling) is the default dispatch policy when you create a POA without specifying the
ServerEnginePolicy.
For ThreadPool, you can set the following properties:
sets the initial idle worker thread check interval to 120 seconds for the default TPool server engine. The default value of this property is 300 seconds. With this setting, the server engine will check the idle state of each worker thread every 120 seconds. If a worker thread has been idle across two consecutive checks, it will be recycled (terminated) at the second check. Therefore, the actual idle thread garbage collection time is between 120 to 240 seconds under the above setting, instead of exactly 120 seconds.
The ThreadPool dispatcher allows a “cooling time” to be set. A thread is said to be “hot” when the GIOP connection being served is potentially readable, either upon creation of the connection or upon the arrival of a request. After the cooling time (in seconds), the thread can be returned to the thread pool. The property can be set statically on server startup or dynamically reconfigured using the property API. For instance, the startup property
We recommend that you use the vbroker.se.default.xxx.tp.xxx property when
vbroker.se.default is set to
iiop_tp. When using with ThreadSession, we recommend that you use the
vbroker.se.iiop_ts.scm.iiop_ts.xxx property.
When using the ThreadSession as the dispatcher type, you must set the
se.default property to
iiop_ts.
In thread-per-session, there are no threadMin,
threadMax,
threadMaxIdle, and
coolingTime dispatcher properties. Only the Connection and Manager properties are valid properties for ThreadSession.
The following properties are used to configure connection management. Properties whose names start with vbroker.se are server-side properties. The client side properties have their names starting with
vbroker.ce.
The command line options for VisiBroker 3.x backward-compatibility are less obvious in terms of whether they are client-side or server-side. However, the connection and thread management options that start with the -ORB prefix set the client-side options whereas the options with the
-OA prefix are used for the server-side options. There are no common properties which are used for both client-side and server-side thread and connection management.
sets the initial maximum connection limitation on this server engine to 128. The default value of this property is unlimited (
0 [zero]). When the server engine reaches this limitation, before accepting a new client connection, the server engine needs to reuse an idle connection. This is called connection swapping. When a new connection arrives at the server, it will try to detach the oldest unused connection. If all the connections are busy, the new connection will be dropped. The client may retry again until some timeout expires.
In the following properties, xxx is the server engine name and
yyy is the server connection manager name:
For this purpose, the server manager needs to be enabled, using the property vbroker.orb.enableServerManager=true, and the properties can be obtained through the server manager query either through the Console or through a command-line utility.
Note that if the property vbroker.se.iiop_tp.scm.iiop_tp.listener.useSelectorPool is set to
true, then each IIOP NIO Listener in the server will be constrained to consume a maximum of
vbroker.se.iiop_tp.scm.iiop_tp.listener.selectorMax instances of
java.nio.channels.Selector at any given time. If that property is not set, or is set to
false, the number of Selectors in use will continue to be unbounded and to be some function of the number of concurrent connections for non-SSL NIO connections.
The ORB garbage collector thread is a normal priority thread. After the expiration of timeout period (specified by the property vbroker.orb.gcTimeout), it wakes up and collects all the resources that are idle and no longer in use. Classes interested in getting collected register themselves with the garbage collector. Such classes are called
collectables. Prominent examples of collectables are threads and connections. Other examples include timeout on various caches like GateKeeper's cache, for example. Most of the collectables null out or properly release the resources (such as closing the connection or terminating a thread's
run method) held by them when they are collected. These resources are later reclaimed by the Java garbage collector.
The main property that controls the garbage collection period is vbroker.orb.gcTimeout. The timeout value is in seconds and the default value is
30 seconds.
Threads and connections define properties for idle timeout. For example, the thread pool dispatcher defines the following property:
The value is in seconds and default value is 300 seconds after which the thread is removed from the thread pool. Similarly, the default Server Connection Manager (
iiop_tp) defines the following idle timeout property for connections.
The value is in seconds and default value is 0(zero) which means a connection never gets closed no matter how long it remains idle. However, if the connection gets dropped, the ORB removes all the references to it and its resources are later collected by Java garbage collector. The ORB garbage collector will only collect connections whose
connectionMaxIdle property is set to a non-zero value.
The various timeout properties and the vbroker.orb.gcTimeout property have a subtle relationship. For example, suppose following properties are specified:
Here the garbage collection timeout period is set to 10 seconds whereas thread and connection timeouts are 5 seconds. The figure below illustrates how these properties interact. Here we have shown a thread,
T1, and a connection,
C1, that have gone idle and are then collected.