Mnesia
Encyclopedia
Mnesia is a distributed
, soft real-time
database management system
written in the Erlang programming language.
for soft real-time distributed
and high-availability computing work related to telecoms. It was not intended as a general office-based data processing
DBMS, nor to replace SQL
-based systems. Instead Mnesia exists to support Erlang, where DBMS-like persistence
is required. It has more in common with embeddable DBMS such as Berkeley DB
than with a SQL database server.
containing an Erlang data structure of any complexity.
A key feature of Mnesia's high-availability approach is that tables can be reconfigured within a schema and relocated between nodes, not only while the database is still running, but even while write operations are still going on.
. It permits easy representation of transactions as a natural feature of Erlang by allowing developers to utilize a single language throughout an application.
transaction
support. The functional block which is run as a transaction is a commonplace Erlang construct called a Functional Object (or Fun) and is called by the single Mnesia statement
Again as a result of the functional nature of Erlang, nesting transactions is simple. It's also possible to distribute transactions across multiple nodes (i.e. separate servers). The semantics of using transactions in this way remains consistent, making it easy to write library code that works equally in either context.
General coding style for Mnesia will always use transactions. For performance reasons, it also supports deliberate "dirty operations" which avoid transactions. These compromise the atomicity and the isolation properties of ACID
, but offer around 10× more throughput. In addition there are also in-memory alternatives, although these lose the durability property of ACID
.
, but based on Erlang. An efficiency benefit that implementation in Erlang confers is the use of a single VM
throughout an application. LYME makes use of this, the Yaws web server also being implemented in Erlang.
Another low-level boost to efficiency is that address space is shared (although safely so, under Erlang) between code and data, including Mnesia's table data.
Computer Science Laboratory. They have been open-sourced "to help encourage the spread of Erlang outside Ericsson." They are published according to the open source Erlang Public License.
daemon, ejabberd
.
Distributed computing
Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...
, soft real-time
Real-time computing
In computer science, real-time computing , or reactive computing, is the study of hardware and software systems that are subject to a "real-time constraint"— e.g. operational deadlines from event to system response. Real-time programs must guarantee response within strict time constraints...
database management system
Database management system
A database management system is a software package with computer programs that control the creation, maintenance, and use of a database. It allows organizations to conveniently develop databases for various applications by database administrators and other specialists. A database is an integrated...
written in the Erlang programming language.
Purpose of Mnesia
As with Erlang, Mnesia was developed by EricssonEricsson
Ericsson , one of Sweden's largest companies, is a provider of telecommunication and data communication systems, and related services, covering a range of technologies, including especially mobile networks...
for soft real-time distributed
Distributed computing
Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...
and high-availability computing work related to telecoms. It was not intended as a general office-based data processing
Data processing
Computer data processing is any process that a computer program does to enter data and summarise, analyse or otherwise convert data into usable information. The process may be automated and run on a computer. It involves recording, analysing, sorting, summarising, calculating, disseminating and...
DBMS, nor to replace SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....
-based systems. Instead Mnesia exists to support Erlang, where DBMS-like persistence
Persistence (computer science)
Persistence in computer science refers to the characteristic of state that outlives the process that created it. Without this capability, state would only exist in RAM, and would be lost when this RAM loses power, such as a computer shutdown....
is required. It has more in common with embeddable DBMS such as Berkeley DB
Berkeley DB
Berkeley DB is a computer software library that provides a high-performance embedded database for key/value data. Berkeley DB is a programmatic software library written in C with API bindings for C++, PHP, Java, Perl, Python, Ruby, Tcl, Smalltalk, and most other programming languages...
than with a SQL database server.
Database model
"Rows" in tables are represented as records that contain a key value and a data field. This data field may in turn be a tupleTuple
In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an n-tuple is a sequence of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair...
containing an Erlang data structure of any complexity.
Relational features
The database model is relational, but isn't what someone familiar with SQL might expect. A database contains tables. Relationships between them are modelled as other tables.A key feature of Mnesia's high-availability approach is that tables can be reconfigured within a schema and relocated between nodes, not only while the database is still running, but even while write operations are still going on.
Coding for Mnesia
The query language of Mnesia is Erlang itself, rather than SQLSQL
SQL is a programming language designed for managing data in relational database management systems ....
. It permits easy representation of transactions as a natural feature of Erlang by allowing developers to utilize a single language throughout an application.
Transactions
Erlang is a functional language. Mnesia builds on this to obtain ACIDACID
In computer science, ACID is a set of properties that guarantee database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction...
transaction
Database transaction
A transaction comprises a unit of work performed within a database management system against a database, and treated in a coherent and reliable way independent of other transactions...
support. The functional block which is run as a transaction is a commonplace Erlang construct called a Functional Object (or Fun) and is called by the single Mnesia statement
mnesia:transaction(F)
. This can lead to clearer source code than the paired BEGIN
/ COMMIT
syntax of SQL, and so avoids its problem of unclosed transactions within a procedure.Again as a result of the functional nature of Erlang, nesting transactions is simple. It's also possible to distribute transactions across multiple nodes (i.e. separate servers). The semantics of using transactions in this way remains consistent, making it easy to write library code that works equally in either context.
General coding style for Mnesia will always use transactions. For performance reasons, it also supports deliberate "dirty operations" which avoid transactions. These compromise the atomicity and the isolation properties of ACID
ACID
In computer science, ACID is a set of properties that guarantee database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction...
, but offer around 10× more throughput. In addition there are also in-memory alternatives, although these lose the durability property of ACID
ACID
In computer science, ACID is a set of properties that guarantee database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction...
.
Efficient execution
Mnesia forms part of the LYME web application stack. This is akin to LAMPLAMP (software bundle)
LAMP is an acronym for a solution stack of free, open source software, referring to the first letters of Linux , Apache HTTP Server, MySQL and PHP , principal components to build a viable general purpose web server.The GNU project is advocating people to use the term "GLAMP" since what is known as...
, but based on Erlang. An efficiency benefit that implementation in Erlang confers is the use of a single VM
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
throughout an application. LYME makes use of this, the Yaws web server also being implemented in Erlang.
Another low-level boost to efficiency is that address space is shared (although safely so, under Erlang) between code and data, including Mnesia's table data.
Origins and licensing
Mnesia (and Erlang) were developed by the EricssonEricsson
Ericsson , one of Sweden's largest companies, is a provider of telecommunication and data communication systems, and related services, covering a range of technologies, including especially mobile networks...
Computer Science Laboratory. They have been open-sourced "to help encourage the spread of Erlang outside Ericsson." They are published according to the open source Erlang Public License.
ejabberd
Mnesia is also an option embedded within the Erlang-based JabberExtensible Messaging and Presence Protocol
Extensible Messaging and Presence Protocol is an open-standard communications protocol for message-oriented middleware based on XML . The protocol was originally named Jabber, and was developed by the Jabber open-source community in 1999 for near-real-time, extensible instant messaging , presence...
daemon, ejabberd
Ejabberd
ejabberd is an XMPP application server, written mainly in the Erlang programming language.It can run under several Unix-like operating systems such as Mac OS X, GNU/Linux, FreeBSD, NetBSD, OpenBSD and OpenSolaris...
.