Is software transactional memory the same as database transactions?

I read a lot about software transactional memory, especially regarding Haskell, but I'm trying to figure out how it differs from database transactions? Are there some advantages that I don't understand with STM?

+6
database concurrency haskell transactional-memory
source share
3 answers

The idea of โ€‹โ€‹a "transaction" in transactional software memory is clearly borrowed from databases. The difference is where the transactions are implemented and how they are used.

STM is a concept of the language level: the sequence of operations does not take effect until the transaction is completed. This usually means that the values โ€‹โ€‹of some global / shared variables only change when a transaction is successful. The property is executed at runtime. There is no inherent concept of durability: the variables involved in a transaction can be purely dynamic (for example, the size of the work queue).

Database operations are a concept of the application level: the sequence of operations with data does not take effect until the transaction. Since this is a database, persistence is fundamental: the meaning of "take effect" inside the database is that the data is stored in some kind of persistent storage.

You can use database and database transactions to implement the STM-style algorithm, but you will lose the ease and convenience (and probably, in most cases, performance) of the implementation at the language level.

+5
source share

Transaction STM has much in common with a database transaction . In particular, the ACID properties important to database developers, STM provides Atomicity and Isolation. Consistency, however, depends on the programmer: you can write STM transactions that, for example, violate invariants of internal data structures. Finally, STM transactions are usually not durable; the results are stored in volatile RAM, and if the machine fails after a successful transaction, the results may be lost. This, in my opinion, is probably the most significant difference between an STM transaction and a database transaction.

+4
source share

STM is mainly used for concurrency, and database transactions are about data consistency.

+1
source share

All Articles