Software Transactional Memory
Transactional memory is an alternative technology to lock-based synchronization and can be compared to database transactions. A transactional memory system is designed for controlling shared memory access in a concurrent programming environment. Similar to database transactions, a transactional memory transaction fulfills atomicity, consistency and isolation properties.
stailaTM
During runtime the system’s metadata, user’s data and logic are constantly accessed and modified concurrently by a number of threads. To maintain consistency in the metadata and to avoid race conditions, some kind of locking mechanism is required. To maintain consistency, old fashioned traditional database transactions are necessary. To address these two combined issues we designed a software transactional memory (STM) system for Mercury called stailaTM. The software transactional memory system is used to protect Mercury’s metadata as well as the user data of the in-memory database. By using stailaTM, we were able to avoid the complexity involved in managing metadata and data of the system.

Concurrency Control in the Core System: Mercury is a complex system with a unified in-memory database and application server. Usually for maintaining consistency, systems employ lock-based synchronization mechanisms, that require running threads in the system to hold all the data structure and metadata locks in correct sequence. Such lock-based synchronization mechanisms are not only complex to handle and prone to hard to catch errors but are also incapable of handling large scale parallelism and scalability efficiently. Thus we came up with a unified STM, designed and implemented from scratch. Apart from providing lock-less, wait-free and automatic concurrency control, stailaTM has several other salient features that makes it ideal for the Mercury platform.
Programming Language Support: The biggest challenge of parallel programming for developers is synchronization of shared memory access by parallel threads. The lock-based synchronization techniques are either too heavy or too complex to handle. However, a software transactional memory can address this problem very well and can be used as an alternative to lock-based protection. With STM a programmer does not need to worry about protecting shared memory access as this is being taken care of by the transactions, just like in traditional databases. In Mercury, stailaTM is designed for transparently maintaining consistency of the core system, but is also exposed to the users via the programming language interface.
The programming language Nitrox (whose syntax is identical to C#), supported by Mercury, has inbuilt STM support. The Nitrox STM support is efficient and performs better than its counterparts because of the fact that the transactions run natively.
Features and Highlights|
Persistency Support: Unlike other STM, stailaTM can be completely ACID compliant. This means it also supports the database feature--durability. In case a transaction commits successfully, all the memory blocks under the current transaction will be written to the secondary storage automatically. AIO Support: To speed up transaction commits and to reduce time taken by the system to upload external data, support for asynchronous I/O has been added. Thereby stailaTM can be configured to persist data on disk either synchronously or asynchronously, depending on the application requirements. It uses I/O aggregation technology to achieve best results. Event Trigger Support: stailaTM supports registration of events by the users. These events are triggered on completion of a transaction, either successfully or unsuccessfully depending on user instruction, and the registered call is invoked. This feature enables Mercury to be used for event-based programming. Nested Transactions: stailaTM supports nested transactions, a powerful feature that enables isolation of a group of dependent transactions from other such transactions. It also assists in rolling back dependent transactions collectively. Exclusive Transactions: For maintaining fairness and for avoiding possible starvation of long running transactions, support for exclusive transactions is also provided by stailaTM. |
