All Projects → jonhoo → Drwmutex

jonhoo / Drwmutex

Licence: mit
Distributed RWMutex in Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Drwmutex

Telepat Api
This is the Telepat API where HTTP calls are made. CRUD operations are not processed here directly. Messages are sent to the Telepat workers where CRUD operations are being taken care of along with client communication (notifications).
Stars: ✭ 335 (+8.77%)
Mutual labels:  synchronization, scalability
Decsync
Synchronize RSS, contacts, calendars, tasks and more without a server
Stars: ✭ 257 (-16.56%)
Mutual labels:  synchronization
CareKitSample-ParseCareKit
An example application of CareKit's OCKSample synchronizing iOS and watchOS to the cloud via ParseCareKit and parse-hipaa
Stars: ✭ 18 (-94.16%)
Mutual labels:  synchronization
syncs
Concurrency and synchronization primitives
Stars: ✭ 81 (-73.7%)
Mutual labels:  synchronization
pyftpsync
Synchronize directories using FTP(S), SFTP, or file system access.
Stars: ✭ 85 (-72.4%)
Mutual labels:  synchronization
syncshell
keep your machine's shell history synchronize
Stars: ✭ 49 (-84.09%)
Mutual labels:  synchronization
laverna-server
Signaling Server for Laverna's P2P Differential Synchronization
Stars: ✭ 22 (-92.86%)
Mutual labels:  synchronization
Chronos
Chronos - A static race detector for the go language
Stars: ✭ 272 (-11.69%)
Mutual labels:  synchronization
hekate
Java Library for Distributed Services
Stars: ✭ 17 (-94.48%)
Mutual labels:  scalability
syscoin
Syscoin is a crypto currency that is universally merge-mineable and offers a unique variety of services including decentralized identities, asset token issuance platform capabilities directly on the blockchain and trustless 0-counterparty interoptibility with the Ethereum blockchain
Stars: ✭ 152 (-50.65%)
Mutual labels:  scalability
hydra-booster
A DHT Indexer node & Peer Router
Stars: ✭ 56 (-81.82%)
Mutual labels:  scalability
theodolite
Theodolite is a framework for benchmarking the horizontal and vertical scalability of cloud-native applications.
Stars: ✭ 20 (-93.51%)
Mutual labels:  scalability
bots
[DEPRECATED] Tradle bot framework, allows to drive user interactions in Tradle mobile and web apps and (soon) using smart contracts for critical functions
Stars: ✭ 20 (-93.51%)
Mutual labels:  scalability
dbsync
Small library for sync android SqlLite database to cloud storage (for now only GDrive)
Stars: ✭ 30 (-90.26%)
Mutual labels:  synchronization
Sessionsync
SessionSync
Stars: ✭ 253 (-17.86%)
Mutual labels:  synchronization
crawley
Crawley the Telegram Beholder
Stars: ✭ 24 (-92.21%)
Mutual labels:  synchronization
state
A Redux-based state container for local-first software, offering seamless synchronization using Automerge CRDTs. (Formerly known as 🐟 Cevitxe).
Stars: ✭ 126 (-59.09%)
Mutual labels:  synchronization
FISCO-BCOS
FISCO BCOS是由微众牵头的金链盟主导研发、对外开源、安全可控的企业级金融区块链底层技术平台。 单链配置下,性能TPS可达万级。提供群组架构、并行计算、分布式存储、可插拔的共识机制、隐私保护算法、支持全链路国密算法等诸多特性。 经过多个机构、多个应用,长时间在生产环境中的实践检验,具备金融级的高性能、高可用性及高安全性。FISCO BCOS is a secure and reliable financial-grade open-source blockchain platform. The platform provides rich features including group architecture, cross-chain communication protoc…
Stars: ✭ 1,603 (+420.45%)
Mutual labels:  synchronization
Redsync.go
*DEPRECATED* Please use https://gopkg.in/redsync.v1 (https://github.com/go-redsync/redsync)
Stars: ✭ 292 (-5.19%)
Mutual labels:  synchronization
Kinto.js
An Offline-First JavaScript Client for Kinto.
Stars: ✭ 268 (-12.99%)
Mutual labels:  synchronization

Distributed Read-Write Mutex in Go

The default Go implementation of sync.RWMutex does not scale well to multiple cores, as all readers contend on the same memory location when they all try to atomically increment it. This repository provides an n-way RWMutex, also known as a "big reader" lock, which gives each CPU core its own RWMutex. Readers take only a read lock local to their core, whereas writers must take all locks in order.

Note that the current implementation only supports x86 processors on Linux; other combinations will revert (automatically) to the old sync.RWMutex behaviour. To support other architectures and OSes, the appropriate cpu_GOARCH.go and cpus_GOOS.go files need to be written. If you have a different setup available, and have the time to write one of these, I'll happily accept patches.

Finding the current CPU

To determine which lock to take, readers use the CPUID instruction, which gives the APICID of the currently active CPU without having to issue a system call or modify the runtime. This instruction is supported on both Intel and AMD processors; ARM CPUs should use the CPU ID register instead. For systems with more than 256 processors, x2APIC must be used, and the EDX register after CPUID with EAX=0xb should be used instead. A mapping from APICID to CPU index is constructed (using CPU affinity syscalls) when the program is started, as it is static for the lifetime of a process. Since the CPUID instruction can be fairly expensive, goroutines will also only periodically update their estimate of what core they are running on. More frequent updates lead to less inter-core lock traffic, but also increases the time spent on CPUID instructions relative to the actual locking.

Stale CPU information. The information of which CPU a goroutine is running on might be stale when we take the lock (the goroutine could have been moved to another core), but this will only affect performance, not correctness, as long as the reader remembers which lock it took. Such moves are also unlikely, as the OS kernel tries to keep threads on the same core to improve cache hits.

Performance

There are many parameters that affect the performance characteristics of this scheme. In particular, the frequency of CPUID checking, the number of readers, the ratio of readers to writers, and the time readers hold their locks, are all important. Since only a single writer is active at the time, the duration a writer holds a lock for does not affect the difference in performance between sync.RWMutex and DRWMutex.

Experiments show that DRWMutex performs better the more cores the system has, and in particular when the fraction of writers is <1%, and CPUID is called at most every 10 locks (this changes depending on the duration a lock is held for). Even on few cores, DRWMutex outperforms sync.RWMutex under these conditions, which are common for applications that elect to use sync.RWMutex over sync.Mutex.

The plot below shows mean performance across 30 runs (using experiment) as the number of cores increases using:

drwmutex-bench -i 5000 -p 0.0001 -n 500 -w 1 -r 100 -c 100

DRWMutex and sync.RWMutex performance comparison

Error bars denote 25th and 75th percentile. Note the drops every 10th core; this is because 10 cores constitute a NUMA node on the machine the benchmarks were run on, so once a NUMA node is added, cross-core traffic becomes more expensive. Performance increases for DRWMutex as more readers can work in parallel compared to sync.RWMutex.

See the go-nuts thread for further discussion.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].