crafting a ready-to-go stm
DESCRIPTION
Crafting a Ready-to-Go STM. Guy Korland Tel Aviv University. DSTM2 Maurice Herlihy et al, A flexible framework … [OOPSLA06]. Limited to Objects. V ery intrusive. Doesn’t support libraries. Bad performance (fork). . @atomic public interface INode { int getValue (); - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/1.jpg)
Guy KorlandTel Aviv University
CRAFTING A READY-TO-GO STM
![Page 2: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/2.jpg)
![Page 3: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/3.jpg)
@atomic public interface INode{int getValue ();void setValue (int value );
}
Factory<INode> factory = Thread.makeFactory(INode.class );final INode node = factory.create();factory result = Thread.doIt(new Callable<Boolean>() {
public Boolean call () { return node.setValue(value);
} });
DSTM2MAURICE HERLIHY ET AL, A FLEXIBLE FRAMEWORK … [OOPSLA06]
• Limited to Objects.
• Very intrusive.
• Doesn’t support libraries.
• Bad performance (fork).
![Page 4: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/4.jpg)
public class Account{
private VBox<Long> balance = new VBox<Long>();
public @Atomic void withdraw(long amount) { balance.put (balance.get() - amount);
}}
JVSTMJOÃO CACHOPO AND ANTÓNIO RITO-SILVA, VERSIONED BOXES AS THE BASIS FOR MEMORY TRANSACTIONS [SCOOL05]
• Doesn’t support libraries.
• Less intrusive.
• Need to “Announce” shared fields
![Page 5: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/5.jpg)
@TransactionalObjectpublic class Stack<E>{
private Node<E> head; @TransactionalMethod public void push(E item) { head = new Node(item, head); } }
MULTIVERSEPETER VEENTJER, SINCE 2009
public static class Node<E> { private Ref<E> value; final Node parent;
Node(E value, Node prev) { this.value = value; this.parent = prev; } }
• Doesn’t support libraries.
• Need to “Announce” shared things.
• But, used commercially (AKKA).
![Page 6: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/6.jpg)
public void update ( double value) {
Atomic {
commission += value;
}
}
ATOM-JAVAB. HINDMAN AND D. GROSSMAN. ATOMICITY VIA SOURCE-TOSOURCETRANSLATION. [MSPC06]
• Add a reserved word.
• Need pre-compilation.
• Doesn’t support libraries.
• Even Less intrusive.
![Page 7: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/7.jpg)
• Annotation based --> @Atomic methods
• Field based access• More scalable than Object bases.• More efficient than word based.
• No reserved words• No need for new compilers (Existing IDEs can be used)
DEUCE STMGuy Korland, Nir Shavit and Pascal Felber, “Noninvasive Java Concurrency with Deuce STM”, [MultiProg '10]
![Page 8: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/8.jpg)
• Supports external libraries• Can be part of a transaction
• Research tool• API for developing and testing new algorithms.
• Real life feedback.
DEUCE STM
![Page 9: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/9.jpg)
public class Bank{ private double commission = 10;
@Atomic(retries=64) public void transaction( Account ac1, Account ac2, double amount){ ac1.balance -= (amount + commission); ac2.balance += amount; } @Atomic public void update( double value){ commission += value; }}
DEUCE STM - API
![Page 10: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/10.jpg)
DEUCE STM - OVERVIEW
![Page 11: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/11.jpg)
public interface Context{
void init ( int atomicBlockId)boolean commit();void rollback ();
void beforeReadAccess( Object obj , long field );Object onReadAccess( Object obj, Object value , long field );int onReadAccess( Object obj, int value , long field );long onReadAccess( Object obj, long value , long field );…void onWriteAccess( Object obj , Object value , long field );void onWriteAccess( Object obj , int value , long field );void onWriteAccess( Object obj , long value , long field );…}
RESEARCH TOOL (CONTEXT- INTERFACE)
![Page 12: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/12.jpg)
BENCHMARKS (SUPERMICRO – 2 X QUAD INTEL)
![Page 13: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/13.jpg)
BENCHMARKS (SUN ULTRASPARC T2 PLUS – 2 X QUAD X 8HT)
![Page 14: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/14.jpg)
BENCHMARKS (AZUL – VEGA2 – 2 X 48)
![Page 15: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/15.jpg)
BENCHMARKS (SUN ULTRASPARC T2 PLUS – 2 X QUAD X 8HT)
![Page 16: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/16.jpg)
![Page 17: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/17.jpg)
![Page 18: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/18.jpg)
BENCHMARK - THE DARK SIDE
1 2 3 4 5 6 7 8 9 100
0.2
0.4
0.6
0.8
1
1.2
LockDeuce
![Page 19: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/19.jpg)
• Contention – Retries, Aborts, Contention Manager …
• STM Algorithm – Data structures, optimistic, pessimistic…
• Semantic – Consistency model, Privatization…
• Instrumented Memory access – Linear overhead on every read/write
OVERHEAD
![Page 20: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/20.jpg)
STATIC ANALYSIS OPTIMIZATIONS
1. Avoiding instrumentation of accesses to immutable and transaction-local memory.
2. Avoiding lock acquisition and releases for thread-local memory.
3. Avoiding readset population in read-only transactions.
![Page 21: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/21.jpg)
NEW STATIC ANALYSIS OPTIMIZATIONS
1. Reduce amount of instrumented memory reads using load elimination.
2. Reduce amount of instrumented memory writes using scalar promotion.
3. Avoid writeset lookups for memory not yet written to.
4. Avoid writeset record keeping for memory that will not be read.
5. Reduce false conflicts by Transaction re-scoping.6. …
Yehuda Afek, Guy Korland, and Arie Zilberstein, “Lowering STM Overhead with Static Analysis”, LCPC'10
![Page 22: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/22.jpg)
1. LOAD ELIMINATION IN ATOMIC BLOCKS
• for (int j = 0; j < nfeatures; j++) {
newCenters[index][j] = newCenters[index][j] + feature[i][j];
}
• if (0 < nfeatures) {
nci = new_centers[index];
fi = feature[i];
for (j = 0; j < nfeatures; j++)
nci[j] = nci[j] + fi[j];
}
5 instrumented memory reads per loop iteration
2 instrumented memory reads per loop iteration
![Page 23: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/23.jpg)
BENCHMARKS – K-MEANS
![Page 24: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/24.jpg)
STM FRIENDLY LIBRARIES• Most of the developers/application only use Data Structures.
@Atomic(retries=64)public void transaction( Map map1, Map map2, String key){ map2.put(key, map1.remove(key));}
We should build a set of “STM Friendly” libraries.
Maurice Herlihy, Eric Koskinen: Transactional boosting: a methodology for highly-concurrent transactional objects. PPOPP’08
![Page 25: Crafting a Ready-to-Go STM](https://reader036.vdocuments.us/reader036/viewer/2022062501/5681617c550346895dd10c28/html5/thumbnails/25.jpg)
SUMMARY WWW.DEUCESTM.ORG