We present Trust<T>, a general, type- and memory-safe alternative to locking in concurrent programs. Instead of synchronizing multi-threaded access to an object of type T with a lock, the programmer may place the object in a Trust<T>. The object is then no longer directly accessible. Instead a designated thread, the object's trustee, is responsible for applying any requested operations to the object, as requested via the Trust<T> API. Locking is often said to offer a limited throughput per lock. Trust<T> is based on delegation, a message-passing technique which does not suffer this per-lock limitation. Instead, per-object throughput is limited by the capacity of the object's trustee, which is typically considerably higher. Our evaluation shows Trust<T> consistently and considerably outperforming locking where lock contention exists, with up to 22x higher throughput in microbenchmarks, and 5-9x for a home grown key-value store, as well as memcached, in situations with high lock contention. Moreover, Trust<T> is competitive with locks even in the absence of lock contention.
翻译:本文提出Trust<T>,一种用于并发程序的通用、类型安全且内存安全的锁替代方案。程序员无需使用锁来同步对类型T对象的多线程访问,而是可以将对象置于Trust<T>中。此后该对象不再可直接访问,而是由一个指定线程(即对象的受托方)负责通过Trust<T> API接收请求,并对对象执行相应操作。传统锁机制常被认为存在单锁吞吐量上限,而Trust<T>基于委托这一消息传递技术,不受单锁吞吐量限制。相反,其单对象吞吐量仅受限于对象受托方的处理能力,该上限通常显著更高。实验评估表明,在存在锁竞争的场景下,Trust<T>始终大幅优于锁机制:微基准测试中吞吐量提升最高达22倍;在高锁竞争环境下,自制键值存储系统与memcached分别实现5-9倍的吞吐量提升。此外,即使在无锁竞争场景中,Trust<T>仍与锁机制保持竞争力。