Hector (API)
Encyclopedia
Hector is a high-level client API
for Apache Cassandra. Named after Hector
, the builder of Troy
in Greek mythology
, it is a substitute for the Cassandra Java Client, or Thrift, that is encapsulated by Hector. It also has Maven
repository access.
, there was a potential to develop a better protocol for application developers. Hector was developed by Ran Tavory as a high-level interface that overlays the shortcomings of Thrift. It is licensed with the MIT License that allows to use, modify, split and change the design.
Over the last couple of days I got the conclusion that the java client I’ve been using so far to speak to cassanrda wasn’t satisfactory. I used the one simply called cassandra-java-client, which is a good start but had some shortcomings I could just not live with (no support for Cassandra v0.5, no JMX and no failover). So I’ve written my own.
distribution algorithm.
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
for Apache Cassandra. Named after Hector
Hector
In Greek mythology, Hectōr , or Hektōr, is a Trojan prince and the greatest fighter for Troy in the Trojan War. As the first-born son of King Priam and Queen Hecuba, a descendant of Dardanus, who lived under Mount Ida, and of Tros, the founder of Troy, he was a prince of the royal house and the...
, the builder of Troy
Troy
Troy was a city, both factual and legendary, located in northwest Anatolia in what is now Turkey, southeast of the Dardanelles and beside Mount Ida...
in Greek mythology
Greek mythology
Greek mythology is the body of myths and legends belonging to the ancient Greeks, concerning their gods and heroes, the nature of the world, and the origins and significance of their own cult and ritual practices. They were a part of religion in ancient Greece...
, it is a substitute for the Cassandra Java Client, or Thrift, that is encapsulated by Hector. It also has Maven
Maven
A maven is a trusted expert in a particular field, who seeks to pass knowledge on to others. The word maven comes from Hebrew, via Yiddish, and means one who understands, based on an accumulation of knowledge.-History:...
repository access.
History
As Cassandra is shipped with the low-level Thrift (protocol)Thrift (protocol)
Thrift is an interface definition language that is used to define and create services for numerous languages. It is used as a remote procedure call framework and was developed at Facebook for "scalable cross-language services development"...
, there was a potential to develop a better protocol for application developers. Hector was developed by Ran Tavory as a high-level interface that overlays the shortcomings of Thrift. It is licensed with the MIT License that allows to use, modify, split and change the design.
Over the last couple of days I got the conclusion that the java client I’ve been using so far to speak to cassanrda wasn’t satisfactory. I used the one simply called cassandra-java-client, which is a good start but had some shortcomings I could just not live with (no support for Cassandra v0.5, no JMX and no failover). So I’ve written my own.
Features
The high-level features of Hector are- A high-level object oriented interface to Cassandra: It is mainly inspired by the Cassandra-java-client. The API is defined in the Keyspace interface.
- Connection pooling. As in high-scale applications, the usual pattern for DAOData Access ObjectIn computer software, a data access object is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer...
s is a large number of reads/writes. It is too expensive for clients to open new connections with each request. So, a client may easily run out of available sockets, if it operates fast enough. Hector provides connection pooling and a nice framework that manages the details. - Failover support: As Cassandra is a distributed data store where hosts (nodesNode (networking)In communication networks, a node is a connection point, either a redistribution point or a communication endpoint . The definition of a node depends on the network and protocol layer referred to...
) may go down. Hector has its own failover policyFailoverIn computing, failover is automatic switching to a redundant or standby computer server, system, or network upon the failure or abnormal termination of the previously active application, server, system, or network...
.Type Comment FAIL_FAST
If an error occurs, it fails ON_FAIL_TRY_ONE_NEXT_AVAILABLE
Tries one more host before giving up ON_FAIL_TRY_ALL_AVAILABLE
Tries all available hosts before giving up - JMX support: Hector exposes JMX for many important runtime metrics, such as number of available connections, idle connections, error statistics.
- Load balancingLoad balancingLoad balancing or load distribution may refer to:*Load balancing , balancing a workload amongst multiple computer devices*Load balancing , the storing of excess electrical power by power stations during low demand periods, for release as demand rises*Weight distribution, the apportioning of weight...
: A simple load balancing exists in the newer version. - Supports the command design pattern to allow clients to concentrate on their business logic and let Hector take care of the required plumbing.
Load balancing
Hector follows two load balancing policies with theLoadBalancingPolicy
interface. The default is called the LeastActiveBalancingPolicy
and routes requests to the pools having the lowest number of active connections, ensuring a good spread of utilisation across the cluster. The RoundRobinBalancingPolicy
is a simple round-robinRound-robin
The term round-robin was originally used to describe a document signed by multiple parties in a circle to make it more difficult to determine the order in which it was signed, thus preventing a ringleader from being identified...
distribution algorithm.
Pooling
TheExhaustedPolicy
determines how the underlying client connection pools are controlled. Currently, three options are available:
Type | Comment |
---|---|
WHEN_EXHAUSTED_FAIL |
Fails acquisition when no more clients are available |
WHEN_EXHAUSTED_GROW |
The pool is automatically increased to react to load increases |
WHEN_EXHAUSTED_BLOCK |
Block on acquisition until a client becomes available (the default) |