views:

122

answers:

3

I've been doing some work on transactional memory and its viability for systems programming (databases, operating systems, servers, etc.). My own experience employing transactions, together with having seen how few communities use transactions in real code, has raised a question: What would convince you, a developer writing production code, to employ transactional memory in your work?

Would it be general adoption? High speed? Improved reliability? By how much?


For those that haven't seen them, memory transactions act like database transactions: operations proceed (apparently) in parallel, and if there is a conflict between two transactions (e.g. they both write the same value), then one or both of the transactions will be rolled back and restarted.

Transactional memory has a few benefits:

  1. Reliability Complete freedom from deadlocks (e.g. wrong-order locking).
  2. Performance Greater speed when there is low contention for locks.
  3. Programmability Fine-grain concurrency control without many synchronization objects to manage.

Even assuming a correct, complete, and fast implementation of TM, however, there are known downsides to this primitive when compared with locks.

  1. Since transactions might execute several times, it is more difficult to predict performance except by empirical experiment.

    Can we reproduce performance bugs?

  2. There are some policy decisions that differ between correct implementations, e.g. What happens to a transaction that ends inside another transaction? Do we commit now, or do we wait?

    Can we adequately understand the local effects of our code?

  3. In order to support irrevocable behavior (e.g. sending the "fire missiles" command) in a transaction that is rolled back, the runtime becomes more complex.

    Can we adequately understand the global effects of our code?

Lastly, as Software implementations will probably be the first to be used (there are already implementations in C, C++, Haskell, Clojure and Scala, to name a few), there actually is a performance problem. With moderate contention, software transactions come with a performance hit.

What is your performance budget? At what point do the benefits outweigh the potential costs?

+3  A: 

I have done some experimenting with TBoost STM and it seems to be usable, though I would not be comfortable using it in a production product yet. The shift in thinking needed is significant though, so I doubt it will catch on unless it shows a compelling benefit in real applications.

I keep hearing that the future is in massively parallel computing as CPUs start to double in cores like they used to double in frequency. So far, 4- and 8-core desktops aren't really showing themselves to be useful for general workloads. I think we have a bit of a chicken-and-egg problem: adoption of parallel machines is waiting on software capable of taking full advantage, while mainstream development of highly parallel software is waiting for ubiquity of highly parallel hardware.

I think perhaps what's needed is an open-source software project to adopt an STM model for something like a web server. A successful project like that would be an excellent model and might help kickstart interest across the software industry by proving that STM is ready for the real world.

Tim Sylvester
+2  A: 

Several things:

1) The Software Transactional Memory (STM) System would have to be robust, reliable, and tested so that it actually works.

2) The performance overhead of an uncontested STM transaction should be comparable to the same routine with a uncontested lock.

3) The STM system must perform significantly better when multiple transactions are pending vs using a lock on contested resources.

Adisak
Basically, my answer boils down to this. Locks are simpler than STM. If STM isn't faster than the locking method, it ain't worth using (since it'd be more complicated and slower). Also, since STM is potentially very complex (in the internal implementation), I would not want to use a STM library unless it was thoroughly tested and used by many others before me.
Adisak
I disagree. I think STM is far far simpler to use than locks. But you're absolutely right that it'd have to be thoroughly tested.
jalf
@Jalf: I didn't say it was harder for the app/use case, I said it's much more complicated in the internal implementation. Heck a spinlock's acquire internal implemenation can be a single atomic swap in a loop followed by a memory barrier and release is a memory barrier followed by a single write to memory. You think you can make an STM implementation simpler than that?
Adisak
@Adisak: fair enough then, I misunderstood you. :) In that case, I obviously agree, the implementation of STM is a lot more complicated than locks, so we might need a bit more convincing before we'll trust a STM library to actually work correctly.
jalf
A: 

I think that there are some criteria that A STM system must provide to user adoption:

Simplicity: The use of transactions is in theory more simple than using lock, but in practice it is not the case there will be no reason to use it.

Performances: The user can accept that the performances be a little bit slower than using locks, but not too much slower.

Interaction with non-transactional world: STM systems that work only on a transaction only world can not succeed for people that works in projects that need to work with a legacy system, or that has other constraints, that can be solved better using other paradigms.

Correctness: The user needs to be confident that the system s/he is using is correct on its foundations as well as in its implementation. Most of the current STM systems are not at the stage of a product, so people can suffer of unstable versions for a moment.

Debugging tools: The debugger tools must be adapted to this new paradigm (at least when the STM system is incorporated on the language), as debugging could be more complex when the same code is executed several times if there are conflicts.

Vicente Botet Escriba