• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    Go
  • License
    Other
  • Created over 12 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Non blocking data structures for Go

gotomic

Non blocking data structures for Go.

Algorithms

The List type is implemented using A Pragmatic Implementation of Non-Blocking Linked-Lists by Timothy L. Harris.

The Hash type is implemented using Split-Ordered Lists: Lock-Free Extensible Hash Tables by Ori Shalev and Nir Shavit with the List type used as backend.

The Transaction type is implemented using OSTM from Concurrent Programming Without Locks by Keir Fraser and Tim Harris with a few tweaks described in https://github.com/zond/gotomic/blob/master/stm.go.

The Treap type uses Transaction to be non blocking and thread safe, and is based (like all other treaps, I guess) on Randomized Search Trees by Cecilia Aragon and Raimund Seidel, but mostly I just used https://github.com/stathat/treap/blob/master/treap.go for reference.

Performance

On my laptop I created benchmarks for a) regular Go map types, b) Go map types protected by sync.RWMutex, c) the gotomic.Hash, d) the gotomic.Treap type and e) the github.com/stathat/treap.Tree type.

The benchmarks for a) and b) can be found at https://github.com/zond/tools/blob/master/tools_test.go#L83, the benchmark for c) at https://github.com/zond/gotomic/blob/master/hash_test.go#L116 and the benchmark for d) and e) at https://github.com/zond/gotomic/blob/master/hash_test.go#L262.

The TL;DR of it all is that the benchmark sets runtime.GOMAXPROCS to be runtime.NumCPU(), and starts that number of goroutines that just mutates and reads the tested mapping.

Last time I ran these tests I got the following results:

a)

BenchmarkNativeMap	 5000000	       567 ns/op

b)

BenchmarkMyMapConc	  200000	     10694 ns/op
BenchmarkMyMap	 1000000	      1427 ns/op

c)

BenchmarkHash      500000	      5146 ns/op
BenchmarkHashConc	  500000	     10599 ns/op

d)

BenchmarkTreap	   50000	     71250 ns/op
BenchmarkTreapConc	   10000	    110843 ns/op

e)

BenchmarkStatHatTreap	 1000000	      4373 ns/op

Also, there are some third party benchmarks available at https://github.com/zond/gotomic/wiki/Benchmarks.

Conclusion: As expected a) is by far the fastest mapping, and it seems that the naive RWMutex wrapped native map b) is much faster at single thread operation, and on a weak laptop about as efficient in multi thread operation, compared to c).

However, on more multicored systems (and also a few smaller ones, strangely enough) c) is more efficient than b).

When it comes to the treap class, I am afraid my implementation of STM is really REALLY inefficient. Maybe because I tried to be clever, or because I just botched it someplace. It seems to work, but I reckon that an RWMutex-wrapped stathat treap would be preferable in most circumstances.

Usage

See https://github.com/zond/gotomic/blob/master/examples/example.go or https://github.com/zond/gotomic/blob/master/examples/profile.go

Also, see the tests.

Documentation

http://go.pkgdoc.org/github.com/zond/gotomic

Bugs

Hash and List have no known bugs and seem to work well.

The Transaction, Handle and Treap types are alpha. They seem to work, but are too slow and untrustworthy :/

I have not tried it on more than my personal laptop however, so if you want to try and force it to misbehave on a heftier machine than a 4 cpu MacBook Air please do!

Improvements

It would be nice to have a Hash#DeleteIfPresent that atomically deletes matching key/value pairs, but since the implementation is slightly harder than trivial and I see no immediate use case I have been too lazy. Tell me if you need it and I might feel motivated :)

More Repositories

1

god

A Go database
Go
531
star
2

qisniff

Go
66
star
3

gosafe

A Go tool to safely compile Go programs by only allowing importing whitelisted packages.
Go
46
star
4

godip

A dippy adjudicator in Go.
Go
27
star
5

diplicity

Open source REST JSON dippy server built on Go and App Engine.
Go
22
star
6

futon

Google Drive on FUSE
Go
15
star
7

diplicity-old

Next generation Droidippy
Go
13
star
8

dipact

JavaScript
12
star
9

godip-history

A dippy judge in Go
Go
11
star
10

android-diplicity

Android client for the diplicity service.
Java
9
star
11

gomonkey

A Go wrapper around SpiderMonkey
Go
6
star
12

stockholm-ai

A berlin-ai inspired game server
Go
5
star
13

treap

Another treap in Go. Somewhat optimized, but still sort of generic.
Go
4
star
14

droidippy

The Droidippy Android client.
Java
4
star
15

unbolted

Object and subscription layer on top of https://github.com/boltdb/bolt
Go
4
star
16

chicklet

A fork of https://bitbucket.org/binet/go-eval to simplify interaction between compiled and interpreted Go
Go
3
star
17

drafty

Go
3
star
18

sshtcelltty

A tcell TTY wrapping a gliderlabs SSH session.
Go
2
star
19

stratum

Lab grounds for an economy simulation game
Go
2
star
20

gomarket

Tools for market simulation in Go
Go
2
star
21

gostatic

Python SimpleHTTPServer in golang.
Go
2
star
22

ecosim

An economy simulation engine based on gomarket
Go
2
star
23

herdis

A Redis herder for simplifying Redis presharding
Ruby
2
star
24

pusher

Simple pub/sub in Go
JavaScript
2
star
25

gopenid

Google OpenID client
Go
2
star
26

commendable

A recommendation engine
Shell
2
star
27

tools

My toolkit
Go
2
star
28

wsubs

WebSocket subscription handling in a RESTy way
Go
2
star
29

tehomelink

Homelink button for Tesla
Go
2
star
30

dogspace-old

C#
1
star
31

replace

CLI tool to search replace recursively.
Go
1
star
32

hackyhack

Go
1
star
33

wildlife

Multiplayer Game of Life
Go
1
star
34

kcwraps

Pretty wrapper around Kyoto Cabinet to emulate putting subsets inside.
Go
1
star
35

virtus

Go
1
star
36

proxy

The simplest possible reverse proxy sending requests to designated backend urls depending on hostname.
Go
1
star
37

mdnsrpc

A wrapper for https://github.com/armon/mdns and net/rpc
Go
1
star
38

isthisfriday

A time zone aware RESTful API service to support isitfriday-type web pages.
Go
1
star
39

henchman

A maximally simple amqp wrapper
Ruby
1
star
40

neunet

golang neural network
Go
1
star
41

goaeoas

Go
1
star
42

snek

ORM based on github.com/jmoiron/sqlx and github.com/mattn/go-sqlite3.
Go
1
star