tile38/vendor/github.com/cespare/xxhash
tidwall 23b016d192 Fix excessive memory usage for objects with TTLs
This commit fixes an issue where Tile38 was using lots of extra
memory to track objects that are marked to expire. This was
creating problems with applications that set big TTLs.

How it worked before:

Every collection had a unique hashmap that stores expiration
timestamps for every object in that collection. Along with
the hashmaps, there's also one big server-wide list that gets
appended every time a new SET+EX is performed.

From a background routine, this list is looped over at least
10 times per second and is randomly searched for potential
candidates that might need expiring. The routine then removes
those entries from the list and tests if the objects matching
the entries have actually expired. If so, these objects are
deleted them from the database. When at least 25% of
the 20 candidates are deleted the loop is immediately
continued, otherwise the loop backs off with a 100ms pause.

Why this was a problem.

The list grows one entry for every SET+EX. When TTLs are long,
like 24-hours or more, it would take at least that much time
before the entry is removed. So for databased that have objects
that use TTLs and are updated often this could lead to a very
large list.

How it was fixed.

The list was removed and the hashmap is now search randomly. This
required a new hashmap implementation, as the built-in Go map
does not provide an operation for randomly geting entries. The
chosen implementation is a robinhood-hash because it provides
open-addressing, which makes for simple random bucket selections.

Issue #502
2019-10-29 11:19:33 -07:00
..
xxhashbench Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhsum Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
.travis.yml Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
LICENSE.txt Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
README.md Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
go.mod Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
go.sum Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_amd64.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_amd64.s Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_other.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_safe.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_test.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_unsafe.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
xxhash_unsafe_test.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00

README.md

xxhash

GoDoc Build Status

xxhash is a Go implementation of the 64-bit xxHash algorithm, XXH64. This is a high-quality hashing algorithm that is much faster than anything in the Go standard library.

This package provides a straightforward API:

func Sum64(b []byte) uint64
func Sum64String(s string) uint64
type Digest struct{ ... }
    func New() *Digest

The Digest type implements hash.Hash64. Its key methods are:

func (*Digest) Write([]byte) (int, error)
func (*Digest) WriteString(string) (int, error)
func (*Digest) Sum64() uint64

This implementation provides a fast pure-Go implementation and an even faster assembly implementation for amd64.

Benchmarks

Here are some quick benchmarks comparing the pure-Go and assembly implementations of Sum64.

input size purego asm
5 B 979.66 MB/s 1291.17 MB/s
100 B 7475.26 MB/s 7973.40 MB/s
4 KB 17573.46 MB/s 17602.65 MB/s
10 MB 17131.46 MB/s 17142.16 MB/s

These numbers were generated on Ubuntu 18.04 with an Intel i7-8700K CPU using the following commands under Go 1.11.2:

$ go test -tags purego -benchtime 10s -bench '/xxhash,direct,bytes'
$ go test -benchtime 10s -bench '/xxhash,direct,bytes'

Projects using this package