Infinispan HotRod Java Client: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Infinispan Concepts =Overview= HotRod is the nat")
 
No edit summary
Line 5: Line 5:
=Overview=
=Overview=


HotRod is the nat
Factory for {@link org.infinispan.client.hotrod.RemoteCache}s.
 
Lifecycle:
 
In order to be able to use an {@link org.infinispan.client.hotrod.RemoteCache}, the {@link org.infinispan.client.hotrod.RemoteCacheManager} must be started first: beside other things, this instantiates connections to Hot Rod server(s). Starting the {@link org.infinispan.client.hotrod.RemoteCacheManager} can be done either at creation by passing start==true to constructor or by using a constructor that does that for you (see C-tor documentation); or after construction by calling {@link #start()}.
 
 
This is an "expensive" object, as it manages a set of persistent TCP connections to the Hot Rod servers. It is recommended to only have one instance of this per JVM, and to cache it between calls to the server (i.e. remoteCache operations).
 
 
{@link #stop()} needs to be called explicitly in order to release all the resources (e.g. threads, TCP connections).
 
Configuration:
 
The cache manager is configured through a {@link Configuration} object passed to the constructor (there are also
* "simplified" constructors that rely on default values). If migrating from a previous version of Infinispan, where {@link Properties}
* were used to configure the RemoteCacheManager, please use the {@link ConfigurationBuilder#withProperties(Properties)} method.
* <p/>
* Below is the list of supported configuration elements:
* <ul>
* <li><tt>infinispan.client.hotrod.request_balancing_strategy</tt>, default = org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy.  For replicated (vs distributed) Hot Rod server clusters, the client balances requests to the
* servers according to this strategy.</li>
* <li><tt>infinispan.client.hotrod.server_list</tt>, default = 127.0.0.1:11222.  This is the initial list of Hot Rod servers to connect to, specified in the following format: host1:port1;host2:port2...
* At least one host:port must be specified.</li>
* <li><tt>infinispan.client.hotrod.force_return_values</tt>, default = false.  Whether or not to implicitly {@link org.infinispan.client.hotrod.Flag#FORCE_RETURN_VALUE} for all calls.</li>
* <li><tt>infinispan.client.hotrod.tcp_no_delay</tt>, default = true.  Affects TCP NODELAY on the TCP stack.</li>
* <li><tt>infinispan.client.hotrod.tcp_keep_alive</tt>, default = false.  Affects TCP KEEPALIVE on the TCP stack.</li>
* <li><tt>infinispan.client.hotrod.transport_factory</tt>, default = org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory - controls which transport to use.  Currently only the TcpTransport is supported.</li>
* <li><tt>infinispan.client.hotrod.marshaller</tt>, default = org.infinispan.marshall.jboss.GenericJBossMarshaller.  Allows you to specify a custom {@link org.infinispan.marshall.Marshaller} implementation to serialize and deserialize user objects. For portable serialization payloads, you should configure the marshaller to be {@link org.infinispan.client.hotrod.marshall.ApacheAvroMarshaller}</li>
* <li><tt>infinispan.client.hotrod.async_executor_factory</tt>, default = org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory.  Allows you to specify a custom asynchroous executor for async calls.</li>
* <li><tt>infinispan.client.hotrod.default_executor_factory.pool_size</tt>, default = 99.  If the default executor is used, this configures the number of threads to initialize the executor with.</li>
* <li><tt>infinispan.client.hotrod.default_executor_factory.queue_size</tt>, default = 100000.  If the default executor is used, this configures the queue size to initialize the executor with.</li>
* <li><tt>infinispan.client.hotrod.hash_function_impl.1</tt>, default = It uses the hash function specified by the server in the responses as indicated in {@link org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory}.  This specifies the version of the hash function and consistent hash algorithm in use, and is closely tied with the HotRod server version used.</li>
* <li><tt>infinispan.client.hotrod.key_size_estimate</tt>, default = 64.  This hint allows sizing of byte buffers when serializing and deserializing keys, to minimize array resizing.</li>
* <li><tt>infinispan.client.hotrod.value_size_estimate</tt>, default = 512.  This hint allows sizing of byte buffers when serializing and deserializing values, to minimize array resizing.</li>
* <li><tt>infinispan.client.hotrod.socket_timeout</tt>, default = 60000 (60 seconds).  This property defines the maximum socket read timeout before giving up waiting for bytes from the server.</li>
* <li><tt>infinispan.client.hotrod.protocol_version</tt>, default = 2.0 .This property defines the protocol version that this client should use. Other valid values include 1.0.</li>
* <li><tt>infinispan.client.hotrod.connect_timeout</tt>, default = 60000 (60 seconds).  This property defines the maximum socket connect timeout before giving up connecting to the server.</li>
* <li><tt>infinispan.client.hotrod.max_retries</tt>, default = 10.  This property defines the maximum number of retries in case of a recoverable error. A valid value should be greater or equals to 0 (zero). Zero mean no retry.</li>
* </ul>
* <br/>
* <i>The following properties are related to connection pooling</i>:
* <p/>
* <ul>
* <li><tt>maxActive</tt> - controls the maximum number of connections per server that are allocated (checked out to client threads, or idle in
* the pool) at one time. When non-positive, there is no limit to the number of connections per server. When maxActive
* is reached, the connection pool for that server is said to be exhausted. The default setting for this parameter is
* -1, i.e. there is no limit.</li>
* <li><tt>maxTotal</tt> - sets a global limit on the number persistent connections that can be in circulation within the combined set of
* servers. When non-positive, there is no limit to the total number of persistent connections in circulation. When
* maxTotal is exceeded, all connections pools are exhausted. The default setting for this parameter is -1 (no limit).
* </li>
* <p/>
* <li><tt>maxIdle</tt> - controls the maximum number of idle persistent connections, per server, at any time. When negative, there is no limit
* to the number of connections that may be idle per server. The default setting for this parameter is -1.</li>
* <p/>
* <li>
* <tt>whenExhaustedAction</tt> - specifies what happens when asking for a connection from a server's pool, and that pool is exhausted. Possible values:
* <ul>
* <li> <tt>0</tt> - an exception will be thrown to the calling user</li>
* <li> <tt>1</tt> - the caller will block (invoke waits until a new or idle connections is available.
* <li> <tt>2</tt> - a new persistent connection will be created and returned (essentially making maxActive meaningless.) </li>
* </ul>
* The default whenExhaustedAction setting is 1.
* </li>
* <p/>
* <li>
* Optionally, one may configure the pool to examine and possibly evict connections as they sit idle in the pool and to
* ensure that a minimum number of idle connections is maintained for each server. This is performed by an "idle connection
* eviction" thread, which runs asynchronously. The idle object evictor does not lock the pool
* throughout its execution.  The idle connection eviction thread may be configured using the following attributes:
* <ul>
* <li><tt>timeBetweenEvictionRunsMillis</tt> - indicates how long the eviction thread should sleep before "runs" of examining idle
* connections. When non-positive, no eviction thread will be launched. The default setting for this parameter is
* 2 minutes </li>
* <li> <tt>minEvictableIdleTimeMillis</tt> - specifies the minimum amount of time that an connection may sit idle in the pool before it
* is eligible for eviction due to idle time. When non-positive, no connection will be dropped from the pool due to
* idle time alone. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this
* parameter is 1800000(30 minutes). </li>
* <li> <tt>testWhileIdle</tt> - indicates whether or not idle connections should be validated by sending an TCP packet to the server,
* during idle connection eviction runs.  Connections that fail to validate will be dropped from the pool. This setting
* has no effect unless timeBetweenEvictionRunsMillis > 0.  The default setting for this parameter is true.
* </li>
* <li><tt>minIdle</tt> - sets a target value for the minimum number of idle connections (per server) that should always be available.
* If this parameter is set to a positive number and timeBetweenEvictionRunsMillis > 0, each time the idle connection
* eviction thread runs, it will try to create enough idle instances so that there will be minIdle idle instances
* available for each server.  The default setting for this parameter is 1. </li>
* </ul>
* </li>
* <li>
* </ul>
*
* @author Mircea.Markus@jboss.com
* @since 4.1
*/

Revision as of 02:30, 16 July 2016

Internal

Overview

Factory for {@link org.infinispan.client.hotrod.RemoteCache}s.

Lifecycle:

In order to be able to use an {@link org.infinispan.client.hotrod.RemoteCache}, the {@link org.infinispan.client.hotrod.RemoteCacheManager} must be started first: beside other things, this instantiates connections to Hot Rod server(s). Starting the {@link org.infinispan.client.hotrod.RemoteCacheManager} can be done either at creation by passing start==true to constructor or by using a constructor that does that for you (see C-tor documentation); or after construction by calling {@link #start()}.


This is an "expensive" object, as it manages a set of persistent TCP connections to the Hot Rod servers. It is recommended to only have one instance of this per JVM, and to cache it between calls to the server (i.e. remoteCache operations).


{@link #stop()} needs to be called explicitly in order to release all the resources (e.g. threads, TCP connections).

Configuration:

The cache manager is configured through a {@link Configuration} object passed to the constructor (there are also

  • "simplified" constructors that rely on default values). If migrating from a previous version of Infinispan, where {@link Properties}
* were used to configure the RemoteCacheManager, please use the {@link ConfigurationBuilder#withProperties(Properties)} method.

*

* Below is the list of supported configuration elements: *

    *
  • infinispan.client.hotrod.request_balancing_strategy, default = org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy. For replicated (vs distributed) Hot Rod server clusters, the client balances requests to the * servers according to this strategy.
  • *
  • infinispan.client.hotrod.server_list, default = 127.0.0.1:11222. This is the initial list of Hot Rod servers to connect to, specified in the following format: host1:port1;host2:port2... * At least one host:port must be specified.
  • *
  • infinispan.client.hotrod.force_return_values, default = false. Whether or not to implicitly {@link org.infinispan.client.hotrod.Flag#FORCE_RETURN_VALUE} for all calls.
  • *
  • infinispan.client.hotrod.tcp_no_delay, default = true. Affects TCP NODELAY on the TCP stack.
  • *
  • infinispan.client.hotrod.tcp_keep_alive, default = false. Affects TCP KEEPALIVE on the TCP stack.
  • *
  • infinispan.client.hotrod.transport_factory, default = org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory - controls which transport to use. Currently only the TcpTransport is supported.
  • *
  • infinispan.client.hotrod.marshaller, default = org.infinispan.marshall.jboss.GenericJBossMarshaller. Allows you to specify a custom {@link org.infinispan.marshall.Marshaller} implementation to serialize and deserialize user objects. For portable serialization payloads, you should configure the marshaller to be {@link org.infinispan.client.hotrod.marshall.ApacheAvroMarshaller}
  • *
  • infinispan.client.hotrod.async_executor_factory, default = org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory. Allows you to specify a custom asynchroous executor for async calls.
  • *
  • infinispan.client.hotrod.default_executor_factory.pool_size, default = 99. If the default executor is used, this configures the number of threads to initialize the executor with.
  • *
  • infinispan.client.hotrod.default_executor_factory.queue_size, default = 100000. If the default executor is used, this configures the queue size to initialize the executor with.
  • *
  • infinispan.client.hotrod.hash_function_impl.1, default = It uses the hash function specified by the server in the responses as indicated in {@link org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory}. This specifies the version of the hash function and consistent hash algorithm in use, and is closely tied with the HotRod server version used.
  • *
  • infinispan.client.hotrod.key_size_estimate, default = 64. This hint allows sizing of byte buffers when serializing and deserializing keys, to minimize array resizing.
  • *
  • infinispan.client.hotrod.value_size_estimate, default = 512. This hint allows sizing of byte buffers when serializing and deserializing values, to minimize array resizing.
  • *
  • infinispan.client.hotrod.socket_timeout, default = 60000 (60 seconds). This property defines the maximum socket read timeout before giving up waiting for bytes from the server.
  • *
  • infinispan.client.hotrod.protocol_version, default = 2.0 .This property defines the protocol version that this client should use. Other valid values include 1.0.
  • *
  • infinispan.client.hotrod.connect_timeout, default = 60000 (60 seconds). This property defines the maximum socket connect timeout before giving up connecting to the server.
  • *
  • infinispan.client.hotrod.max_retries, default = 10. This property defines the maximum number of retries in case of a recoverable error. A valid value should be greater or equals to 0 (zero). Zero mean no retry.
  • *
* 
* The following properties are related to connection pooling:

*

*

    *
  • maxActive - controls the maximum number of connections per server that are allocated (checked out to client threads, or idle in * the pool) at one time. When non-positive, there is no limit to the number of connections per server. When maxActive * is reached, the connection pool for that server is said to be exhausted. The default setting for this parameter is * -1, i.e. there is no limit.
  • *
  • maxTotal - sets a global limit on the number persistent connections that can be in circulation within the combined set of * servers. When non-positive, there is no limit to the total number of persistent connections in circulation. When * maxTotal is exceeded, all connections pools are exhausted. The default setting for this parameter is -1 (no limit). *
  • *

    *

  • maxIdle - controls the maximum number of idle persistent connections, per server, at any time. When negative, there is no limit * to the number of connections that may be idle per server. The default setting for this parameter is -1.
  • *

    *

  • * whenExhaustedAction - specifies what happens when asking for a connection from a server's pool, and that pool is exhausted. Possible values: *
      *
    • 0 - an exception will be thrown to the calling user
    • *
    • 1 - the caller will block (invoke waits until a new or idle connections is available. *
    • 2 - a new persistent connection will be created and returned (essentially making maxActive meaningless.)
    • *
    * The default whenExhaustedAction setting is 1.
    
    *
  • *

    *

  • * Optionally, one may configure the pool to examine and possibly evict connections as they sit idle in the pool and to * ensure that a minimum number of idle connections is maintained for each server. This is performed by an "idle connection * eviction" thread, which runs asynchronously. The idle object evictor does not lock the pool * throughout its execution. The idle connection eviction thread may be configured using the following attributes: *
      *
    • timeBetweenEvictionRunsMillis - indicates how long the eviction thread should sleep before "runs" of examining idle * connections. When non-positive, no eviction thread will be launched. The default setting for this parameter is * 2 minutes
    • *
    • minEvictableIdleTimeMillis - specifies the minimum amount of time that an connection may sit idle in the pool before it * is eligible for eviction due to idle time. When non-positive, no connection will be dropped from the pool due to * idle time alone. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this * parameter is 1800000(30 minutes).
    • *
    • testWhileIdle - indicates whether or not idle connections should be validated by sending an TCP packet to the server, * during idle connection eviction runs. Connections that fail to validate will be dropped from the pool. This setting * has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is true. *
    • *
    • minIdle - sets a target value for the minimum number of idle connections (per server) that should always be available. * If this parameter is set to a positive number and timeBetweenEvictionRunsMillis > 0, each time the idle connection * eviction thread runs, it will try to create enough idle instances so that there will be minIdle idle instances * available for each server. The default setting for this parameter is 1.
    • *
    *
  • *
  • *
*
* @author Mircea.Markus@jboss.com
* @since 4.1
*/