Clojure High Performance Programming by Kumar Shantanu
Author:Kumar, Shantanu [Kumar, Shantanu]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2015-09-28T16:00:00+00:00
Upping transaction consistency with ensure
Clojure's transactional consistency is a good balance between performance and safety. However, at times, we may need the Serializable consistency in order to preserve the correctness of the transaction. Concretely, in the face of the transaction retries, when a transaction's correctness depends on the state of a ref, in the transaction, wherein the ref is updated simultaneously in another transaction, we have a condition called "write skew". The Wikipedia entry on the write skew, https://en.wikipedia.org/wiki/Snapshot_isolation, describes it well, but let's see a more concrete example. Let's say we want to design a flight simulation system with two engines, and one of the system level constraints is not to switch off both engines at the same time. If we model each engine as a ref, and certain maneuvers do require us to switch off an engine, we must ensure that the other engine is on. We can do it with ensure. Usually, ensure is required when maintaining a consistent relationship (invariants) across the refs is necessary. This cannot be ensured by the validator functions, because they do not come into play until the transaction commits. The validator functions will see the same value hence cannot help.
The write-skew can be solved using the namesake ensure function that essentially prevents a ref from modification by other transactions. It is similar to a locking operation, but in practice, it provides better concurrency than the explicit read-and-update operations, when the retries are expensive. Using ensure is quite simple—(ensure ref-object). However, it may be performance-wise expensive, due to the locks it holds during the transaction. Managing performance with ensure involves a trade-off between the retry latency, and the lost throughput due to the ensured state.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ajax | Assembly Language Programming |
Borland Delphi | C & C++ |
C# | CSS |
Compiler Design | Compilers |
DHTML | Debugging |
Delphi | Fortran |
Java | Lisp |
Perl | Prolog |
Python | RPG |
Ruby | Swift |
Visual Basic | XHTML |
XML | XSL |
Deep Learning with Python by François Chollet(11823)
Hello! Python by Anthony Briggs(9351)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9322)
The Mikado Method by Ola Ellnestam Daniel Brolund(9288)
Dependency Injection in .NET by Mark Seemann(8835)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7835)
Grails in Action by Glen Smith Peter Ledbrook(7286)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7263)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7096)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5933)
Kotlin in Action by Dmitry Jemerov(4617)
Practical Vim (for Kathryn Amaral) by Drew Neil(3718)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3582)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3334)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3223)
Learning Java by Patrick Niemeyer & Daniel Leuck(2861)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2821)
Mastering Java 9 by Dr. Edward Lavieri(2564)
Learning Concurrency in Python by Elliot Forbes(2540)