• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 3 years ago

Reviews

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

Repository Details

Best-effort CPU-local sharded values for Go

percpu

Go Reference

Percpu is a Go package to support best-effort CPU-local sharded values.

This package is something of an experiment. See Go issue #18802 for discussion about adding this functionality into the Go standard library. I used an API suggested by Bryan Mills (@bcmills) on that issue.

IMPORTANT CAVEATS

  • This package uses go:linkname to access unexported functions from inside the Go runtime. Those could be changed or removed in a future Go version, breaking this package.
  • The code in this package assumes that GOMAXPROCS does not change. If the value of GOMAXPROCS changes (via a call to runtime.GOMAXPROCS) after creating a Values, then Values.Get may panic.
  • It may be tempting to use this package to solve problems for which there are better solutions that do not break key abstractions of the runtime.

See When to use percpu for a discussion about when this package may or may not be appropriate.

Benchmarks

A best-case scenario for percpu is a shared counter being incremented as fast as possible. This is exercised by the benchmark for percpu.Counter, which compares the performance of Counter against a mutex-guarded integer and a single atomically-incremented integer.

Below are the results (limiting the code to use 1, 2, 4, ..., 96 cores on a 96-core machine) plotted as increments/sec.

benchmark image

With the mutex and the single atomic, adding more CPUs increases cache contention and the total number of increments/sec goes down. By contrast, the percpu.Counter scales up linearly in the number of CPUs. With all 96 CPUs, percpu.Counter runs several orders of magnitude faster than the other counters:

total incs/sec 1-goroutine inc latency slowdown vs. percpu.Counter
mutex 1.9M 50 μs 3727×
atomic 49M 2.0 μs 145×
percpu 7.1B 13.5 ns

More Repositories

1

reflex

Run a command when files change
Go
3,151
star
2

xxhash

A Go implementation of the 64-bit xxHash algorithm (XXH64)
Go
1,597
star
3

vim-toml

Vim syntax for TOML
Vim Script
624
star
4

ryu

A Go implementation of the Ryu algorithm for converting floating-point numbers to strings
Go
91
star
5

pastedown

Easy-to-use markdown-formatting pastebin
Go
90
star
6

prettybench

Format Go's benchmarking output
Go
87
star
7

go-smaz

A pure Go implementation of the smaz compression library for short strings.
Go
77
star
8

mph

Minimal perfect hashing in Go
Go
71
star
9

deplist

List the external dependencies of a Go package.
Go
63
star
10

gost

A largely compatible statsd daemon implementation in Go.
Go
55
star
11

goclj

Clojure parsing in Go
Go
37
star
12

go-tetris

A console-based tetris implementation in go.
Go
31
star
13

frosty

A raytracer, for fun
Go
24
star
14

saturday

A small SAT solver in Go
Go
23
star
15

markdownd

A markdown renderer and server for your command line.
Go
19
star
16

misc

Experiments and bad ideas
Go
19
star
17

stats

A commandline utility for summary statistics
Go
18
star
18

discoball

A simple stream filter to highlight patterns
Ruby
17
star
19

vim-sbd

Smart buffer closing. Mirror of repo by Orphée Lafond-Lummis.
Vim Script
17
star
20

vim-config

My personal vim configuration.
Vim Script
17
star
21

permute

Permutations for Go
Go
16
star
22

sub

Find/replace across files.
Go
14
star
23

vim-go-templates

Vim syntax highlighting for Go templates.
Vim Script
13
star
24

cbor

A Go implementation of CBOR (compact binary object representation).
Go
13
star
25

kvcache

An expiring key/value cache with a Redis interface
Go
11
star
26

go-localpath

Shell script for managing Go projects with vendored dependencies.
Shell
11
star
27

carlisle

Window control shortcuts for EWMH-compliant X window managers
Go
10
star
28

go-trie

A pure Go trie (prefix tree) implementation.
Go
8
star
29

dotfiles

Personal dotfiles, vim config, little scripts, etc.
Shell
8
star
30

pinion

A lightweight asset management system for Rack
Ruby
8
star
31

flake

Find test flakes
Go
6
star
32

playctrl

Control Google Play in Chrome via global shortcuts.
Go
6
star
33

boggle-solver

A simple boggle solver written for fun.
Ruby
6
star
34

ruby-dedent

A tiny addition to add a dedent method for Ruby strings
Ruby
6
star
35

vjde

Mirror of http://www.vim.org/scripts/script.php?script_id=1213
Vim Script
6
star
36

goproc

Parsing and tools for the Linux /proc pseudo-file system
Go
5
star
37

cp

File copying for Go
Go
5
star
38

tabular

Write tabular text
Go
5
star
39

sitkin

A static site generator.
Go
5
star
40

next

Experimental packages using generics
Go
5
star
41

diff

Go library for diffing files and readers.
Go
5
star
42

subcmd

A minimal Go package for CLI interfaces with sub-commands
Go
4
star
43

hprofviz

HProf output visualizer
Go
4
star
44

tsprefix

Prepend timestamps to each line of standard input
Go
4
star
45

jquery-ajax-retry

A simple jquery 'plugin' to retry ajax requests.
CoffeeScript
4
star
46

git-scripts

My personal git helper scripts
Ruby
4
star
47

assetserver

Go file server for web assets
Go
4
star
48

cron

A Go implementation of the cron scheduling format
Go
4
star
49

memstats

Go
4
star
50

tumblestone

Quick solver for tumblestone
Go
3
star
51

lp

list processes
Go
3
star
52

vim-bclose

Clone of bclose script.
Vim Script
3
star
53

mxml.vim

MXML syntax highlighting
Vim Script
3
star
54

flagconf

Easy TOML + flags configuration for Go programs.
Go
3
star
55

shadow

Expose Graphite metrics with an HTTP API
Go
3
star
56

go-apachelog

A logger for go servers that uses the apache common log format.
Go
3
star
57

gomaxprocs

A slightly better interface for accessing Go's runtime.GOMAXPROCS.
Go
3
star
58

deep_hash

A very small Ruby gem to manage multi-level default hashes.
Ruby
3
star
59

aoc2020

Advent of Code 2020
Go
3
star
60

glp

A code and dependency organization tool for Go
Go
2
star
61

argf

A Go implementation of Ruby's ARGF
Go
2
star
62

weave

Simple parallel SSH.
Ruby
2
star
63

hutil

Go net/http utilities.
Go
2
star
64

grb

go remote build
Go
2
star
65

kp

Keepass database manipulation
Go
2
star
66

guard-restarter

A Guard plugin to start something (like a server) and restart it when files change.
Ruby
2
star
67

window

Go package for maintaining a fixed window of a stream.
Go
2
star
68

ruby-complete

A ruby interface to bash command completion
Ruby
2
star
69

datef

Parse and print dates
Go
2
star
70

webtest

External copy of golang.org/x/website/internal/webtest
Go
2
star
71

jsonpath

Search for keys in nested JSON structures
Go
2
star
72

hmux

An HTTP muxer
Go
2
star
73

jquery-pixel-align

A jquery plugin to align SVGs to pixel boundaries.
HTML
2
star
74

git-heart

git ♥
1
star
75

usd

Go package for US Dollars
Go
1
star
76

cespare-brew-formulae

My personal brew formulae
Ruby
1
star
77

chunk

Read an arbitrary chunk from a file
Go
1
star
78

erebus

An easy-to-configure and flexible reverse routing proxy for development.
Go
1
star
79

githelpers

Helper tools for git
Go
1
star
80

fswatch

A small library to add a few features to github.com/fsnotify/fsnotify.
Go
1
star
81

dtd.vim

DTD syntax highlighting
Vim Script
1
star
82

wait

A Go package providing an extended version of sync.WaitGroup
Go
1
star
83

qs

Quickly take a screenshot and upload to Imgur (on Linux)
Shell
1
star
84

aoc2018

Advent of Code 2018
Go
1
star
85

ez-nginx-proxy

An nginx wrapper for simple reverse proxies in development.
Ruby
1
star
86

intelbacklight

An alternative for xbacklight that works with intel graphics
Go
1
star
87

pratbot

Go prat bot.
Go
1
star
88

srcstats

A source code analysis thing
Go
1
star
89

matasano

Solutions to the Matasano crypto challenges
Go
1
star
90

scrumcard

Planning Poker web app
JavaScript
1
star
91

cespare-snippets

Personal snipmate snippets
1
star
92

aoc2019

Advent of Code 2019
Go
1
star
93

rrproxy

A very simple routing reverse proxy built on Goliath.
Ruby
1
star
94

tlist

Minimal command-line TODO-list manager
Ruby
1
star