Deployment

Takeru INOUE

This article is described based on Kai version 0.4 and Erlang R13B.

Installing Erlang

Here, we show how to install Erlang with binary packages, since Erlang is provided as a binary package in most of major platforms.

Fedora

% yum install erlang

Debian (Ubuntu)

% apt-get install erlang

FreeBSD

% portinstall erlang

Mac OS X

% port install erlang

For Windows, you can find an installer at erlang.org.

Detaching Erlang Shell from Console

This section describes how to detach Erlang shell from the console. This is an important feature in production deployment, because you can run Kai nodes as a background task.

To detach Erlang shell, use "-sname", "-detached", and "-eval" options when starting a Kai node, as follows:

% erl -sname node -detached -pa ebin -config kai -eval 'application:start(kai).'

To attach the shell, use "-sname" and "-remsh" options, as follows:

~~~~~~~
% erl -sname controller -remsh kai@hostname -s

By attaching the shell, you can send Kai commands like the function "kai_hash:node_list/0".

Type "^G" and "q", and back to the console without exiting the Erlang shell.

We show brief explanation on the options.

Description of argumentsfor erl command.

 Name             | Description
 ---------------- | ---------------------------------------------------------
 -sname Name      | Gives name to the Erlang shell.
 -detached        | Starts the Erlang detached from the console.
 -remsh Name@Host | Starts Erlang with a remote shell connected to Name@Host.
 -eval Expr       | Performs the specified expression.

Increasing the Maximum Number of File Descriptors
===

The maximum number of file descriptors should be changed if you encounter the EMFILE error, since the Kai node opens many sockets and files (when dets). It is defined by the following parameters. See manuals of each platform in detail.

Linux

 Parameter   | Filename
 ----------- | -------------------------
 nofile      | /etc/security/limits.conf
 fs.file-max | /etc/sysctl.conf

BSD

 Parameter                           | Filename
 ----------------------------------- | ----------------
 openfiles                           | /etc/login.conf
 kern.maxfiles, kern.maxfilesperproc | /etc/sysctl.conf

Expanding Socket Buffer
===

The socket buffer should be expanded under high network loads, by editing the following parameters. See manuals of each platform in detail.

Linux

 Parameter                                                 | Filename
 --------------------------------------------------------- | ----------------
 net.core.rmem_max, net.core.wmem_max, net.core.optmem_max | /etc/sysctl.conf

BSD

 Parameter                                                           | Filename
 ------------------------------------------------------------------- | ----------------
 net.inet.tcp.sendspace, net.inet.tcp.recvspace, kern.ipc.maxsockbuf | /etc/sysctl.conf

Plugin for Ruby on Rails
===

Ruby on Rails has a plugin named [ActiveKai](http://github.com/sawamur/active_kai) for accessing to the Kai cluster. Your model class is supposed to be interited from ActiveKai like ActiveRecord. The cluster nodes are specified as follows:

class Book < ActiveKai
kai_servers ['192.168.10.1:11211','192.168.10.2:11211','192.168.10.3:11211']
end

A object of this model class must be created with an ":id" that is a key. The "save" method serializes and stores the object into the Kai cluster. By issuing the "find" method of the model class with the key, the object can be retrieved and deserialized.

book = Book.new(:id => 12345,:title => "Learning Erlang",:author => "John")
puts book.author #=> john
book.save

b2 = Book.find(12345)
b2.title = "Learning Ruby"
b2.save
~~~~~~

Statistics

Statistics for the Kai node can be retrieved by issuing stats command of memcache APIs. The parameters without "kai_" or "erlang_" prefix are in common with memcache APIs. Some of Kai related parameters are explained in [Configuration] in detail.

Statistics

Name Description
uptime Number of seconds this server has been running.
time Current UNIX time according to the server.
version Version string of the Kai node.
bytes Current number of bytes used by the Kai node to store items.
curr_items Current number of items stored by the Kai node.
curr_connections Number of open connections.
cmd_get Cumulative number of successful retrieval requests processed by the Kai node.
cmd_set Cumulative number of successful storage requests processed by the Kai node.
bytes_read Total number of bytes transferred from the Kai node.
bytes_write Total number of bytes transferred to the Kai node.
kai_node Socket address for internal RPC in the Kai node.
kai_quorum Parameters for the quorum protocol; i.e. N:R:W.
kai_number_of_buckets Number of buckets in the Kai cluster.
kai_number_of_virtual_nodes Number of virtual nodes in the Kai node.
kai_store Storage type used by the Kai node; ets or dets.
kai_curr_nodes Membership in the current cluster.
kai_unreconciled_get Cumulative number of retrieval requests with confliction.
erlang_procs Number of Erlang processes.
erlang_version Version string of Erlang.

Drawing Statistics Information

Some statistics (bytes, curr_items, cmd_get, cmd_set, bytes_read, and bytes_write) can be drawn by Cacti, which is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality. Details are found in "contrib/cacti/README" in the archive.

Cacti graph
Fig.1: An example of a Cacti graph, which draws cmd_get and cmd_set.

This article was originally published in Japanese at gihyo.jp June 2009.


Related

Wiki: Configuration
Wiki: Getting Started
Wiki: Home