Showing with 6,859 additions and 601 deletions.
  1. +1 −1 .github/CODEOWNERS
  2. +1 −0 .github/ISSUE_TEMPLATE
  3. +24 −0 .github/workflows/main.yml
  4. +1 −0 .go-version
  5. +0 −11 .travis.yml
  6. +118 −0 CHANGELOG.md
  7. +15 −3 README.md
  8. +231 −255 cache.go
  9. +394 −79 cache_test.go
  10. +61 −0 contrib/demo/node.go
  11. +28 −0 contrib/demo/node_allocator.go
  12. +9 −0 contrib/demo/node_golang.go
  13. +21 −0 contrib/demo/node_jemalloc.go
  14. +2 −0 contrib/memtest/.gitignore
  15. +16 −0 contrib/memtest/README.md
  16. +175 −0 contrib/memtest/main.go
  17. +46 −0 contrib/memtest/nojemalloc.go
  18. +26 −0 contrib/memtest/withjemalloc.go
  19. +1 −0 contrib/memtestc/.gitignore
  20. +108 −0 contrib/memtestc/list.c
  21. +13 −2 go.mod
  22. +15 −7 go.sum
  23. +249 −0 metrics.go
  24. +93 −84 policy.go
  25. +26 −14 policy_test.go
  26. +9 −0 sketch_test.go
  27. +67 −74 store.go
  28. +95 −60 store_test.go
  29. +5 −4 stress_test.go
  30. +22 −0 test.sh
  31. +15 −3 ttl.go
  32. +403 −0 z/allocator.go
  33. +194 −0 z/allocator_test.go
  34. +11 −3 z/bbloom.go
  35. +710 −0 z/btree.go
  36. +531 −0 z/btree_test.go
  37. +544 −0 z/buffer.go
  38. +303 −0 z/buffer_test.go
  39. +42 −0 z/calloc.go
  40. +14 −0 z/calloc_32bit.go
  41. +14 −0 z/calloc_64bit.go
  42. +172 −0 z/calloc_jemalloc.go
  43. +37 −0 z/calloc_nojemalloc.go
  44. +107 −0 z/calloc_test.go
  45. +217 −0 z/file.go
  46. +39 −0 z/file_default.go
  47. +37 −0 z/file_linux.go
  48. +311 −0 z/flags.go
  49. +100 −0 z/flags_test.go
  50. +205 −0 z/histogram.go
  51. +80 −0 z/histogram_test.go
  52. +44 −0 z/mmap.go
  53. +59 −0 z/mmap_darwin.go
  54. +97 −0 z/mmap_linux.go
  55. +44 −0 z/mmap_plan9.go
  56. +55 −0 z/mmap_unix.go
  57. +95 −0 z/mmap_windows.go
  58. +11 −0 z/rtutil.go
  59. +23 −0 z/simd/add_test.go
  60. +80 −0 z/simd/asm2.go
  61. +127 −0 z/simd/baseline.go
  62. +51 −0 z/simd/search.go
  63. +60 −0 z/simd/search_amd64.s
  64. +6 −0 z/simd/stub_search_amd64.go
  65. +97 −1 z/z.go
  66. +52 −0 z/z_test.go
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CODEOWNERS info: https://help.github.com/en/articles/about-code-owners
# Owners are automatically requested for review for PRs that changes code
# that they own.
* @manishrjain @karlmcguire @martinmr @anurags92
* @manishrjain @martinmr @jarifibrahim
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**GitHub Issues are deprecated. Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/ristretto/40) for reporting issues about this repository.**
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This is a basic workflow to help you get started with Actions

name: Issue Closer

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
issues:
types: [ opened ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Close Issue
uses: peter-evans/close-issue@v1.0.1
with:
comment: |
**Use [Discuss Issues](https://discuss.dgraph.io/c/issues/35/ristretto/40) for reporting issues about this repository.**
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.17.11
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

118 changes: 118 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,129 @@ and this project will adhere to [Semantic Versioning](http://semver.org/spec/v2.

## Unreleased

## [0.1.0] - 2021-06-03

[0.1.0]: https://github.com/dgraph-io/ristretto/compare/v0.1.0..v0.0.3
This release contains bug fixes and improvements to Ristretto. It also contains
major updates to the z package. The z package contains types such as Tree (B+
tree), Buffer, Mmap file, etc. All these types are used in Badger and Dgraph to
improve performance and reduce memory requirements.

### Changed
- Make item public. Add a new onReject call for rejected items. (#180)

### Added
- Use z.Buffer backing for B+ tree (#268)
- expose GetTTL function (#270)
- docs(README): Ristretto is production-ready. (#267)
- Add IterateKV (#265)
- feat(super-flags): Add GetPath method in superflags (#258)
- add GetDuration to SuperFlag (#248)
- add Has, GetFloat64, and GetInt64 to SuperFlag (#247)
- move SuperFlag to Ristretto (#246)
- add SuperFlagHelp tool to generate flag help text (#251)
- allow empty defaults in SuperFlag (#254)
- add mmaped b+ tree (#207)
- Add API to allow the MaxCost of an existing cache to be updated. (#200)
- Add OnExit handler which can be used for manual memory management (#183)
- Add life expectancy histogram (#182)
- Add mechanism to wait for items to be processed. (#184)

### Fixed
- change expiration type from int64 to time.Time (#277)
- fix(buffer): make buffer capacity atleast defaultCapacity (#273)
- Fixes for z.PersistentTree (#272)
- Initialize persistent tree correctly (#271)
- use xxhash v2 (#266)
- update comments to correctly reflect counter space usage (#189)
- enable riscv64 builds (#264)
- Switch from log to glog (#263)
- Use Fibonacci for latency numbers
- cache: fix race when clearning a cache (#261)
- Check for keys without values in superflags (#259)
- chore(perf): using tags instead of runtime callers to improve the performance of leak detection (#255)
- fix(Flags): panic on user errors (#256)
- fix SuperFlagHelp newline (#252)
- fix(arm): Fix crashing under ARMv6 due to memory mis-alignment (#239)
- Fix incorrect unit test coverage depiction (#245)
- chore(histogram): adding percentile in histogram (#241)
- fix(windows): use filepath instead of path (#244)
- fix(MmapFile): Close the fd before deleting the file (#242)
- Fixes CGO_ENABLED=0 compilation error (#240)
- fix(build): fix build on non-amd64 architectures (#238)
- fix(b+tree): Do not double the size of btree (#237)
- fix(jemalloc): Fix the stats of jemalloc (#236)
- Don't print stuff, only return strings.
- Bring memclrNoHeapPointers to z (#235)
- increase number of buffers from 32 to 64 in allocator (#234)
- Set minSize to 1MB.
- Opt(btree): Use Go memory instead of mmap files
- Opt(btree): Lightweight stats calculation
- Put padding internally to z.Buffer
- Chore(z): Add SetTmpDir API to set the temp directory (#233)
- Add a BufferFrom
- Bring z.Allocator and z.AllocatorPool back
- Fix(z.Allocator): Make Allocator use Go memory
- Updated ZeroOut to use a simple for loop. (#231)
- Add concurrency back
- Add a test to check concurrency of Allocator.
- Fix(buffer): Expose padding by z.Buffer's APIs and fix test (#222)
- AllocateSlice should Truncate if the file is not big enough (#226)
- Zero out allocations for structs now that we're reusing Allocators.
- Fix the ristretto substring
- Deal with nil z.AllocatorPool
- Create an AllocatorPool class.
- chore(btree): clean NewTree API (#225)
- fix(MmapFile): Don't error out if fileSize > sz (#224)
- feat(btree): allow option to reset btree and mmaping it to specified file. (#223)
- Use mremap on Linux instead of munmap+mmap (#221)
- Reuse pages in B+ tree (#220)
- fix(allocator): make nil allocator return go byte slice (#217)
- fix(buffer): Make padding internal to z.buffer (#216)
- chore(buffer): add a parent directory field in z.Buffer (#215)
- Make Allocator concurrent
- Fix infinite loop in allocator (#214)
- Add trim func
- Use allocator pool. Turn off freelist.
- Add freelists to Allocator to reuse.
- make DeleteBelow delete values that are less than lo (#211)
- Avoid an unnecessary Load procedure in IncrementOffset.
- Add Stats method in Btree.
- chore(script): fix local test script (#210)
- fix(btree): Increase buffer size if needed. (#209)
- chore(btree): add occupancy ratio, search benchmark and compact bug fix (#208)
- Add licenses, remove prints, and fix a bug in compact
- Add IncrementOffset API for z.buffers (#206)
- Show count when printing histogram (#201)
- Zbuffer: Add LenNoPadding and make padding 8 bytes (#204)
- Allocate Go memory in case allocator is nil.
- Add leak detection via leak build flag and fix a leak during cache.Close.
- Add some APIs for allocator and buffer
- Sync before truncation or close.
- Handle nil MmapFile for Sync.
- Public methods must not panic after Close() (#202)
- Check for RD_ONLY correctly.
- Modify MmapFile APIs
- Add a bunch of APIs around MmapFile
- Move APIs for mmapfile creation over to z package.
- Add ZeroOut func
- Add SliceOffsets
- z: Add TotalSize method on bloom filter (#197)
- Add Msync func
- Buffer: Use 256 GB mmap size instead of MaxInt64 (#198)
- Add a simple test to check next2Pow
- Improve memory performance (#195)
- Have a way to automatically mmap a growing buffer (#196)
- Introduce Mmapped buffers and Merge Sort (#194)
- Add a way to access an allocator via reference.
- Use jemalloc.a to ensure compilation with the Go binary
- Fix up a build issue with ReadMemStats
- Add ReadMemStats function (#193)
- Allocator helps allocate memory to be used by unsafe structs (#192)
- Improve histogram output
- Move Closer from y to z (#191)
- Add histogram.Mean() method (#188)
- Introduce Calloc: Manual Memory Management via jemalloc (#186)

## [0.0.3] - 2020-07-06

Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Ristretto
[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/dgraph-io/ristretto)
[![Go Report Card](https://img.shields.io/badge/go%20report-A%2B-brightgreen)](https://goreportcard.com/report/github.com/dgraph-io/ristretto)
[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://gocover.io/github.com/dgraph-io/ristretto)
[![Coverage](https://gocover.io/_badge/github.com/dgraph-io/ristretto)](https://gocover.io/github.com/dgraph-io/ristretto)
![Tests](https://github.com/dgraph-io/ristretto/workflows/tests/badge.svg)

Ristretto is a fast, concurrent cache library built with a focus on performance and correctness.

The motivation to build Ristretto comes from the need for a contention-free
cache in [Dgraph][].

**Use [Discuss Issues](https://discuss.dgraph.io/tags/c/issues/35/ristretto/40) for reporting issues about this repository.**

[Dgraph]: https://github.com/dgraph-io/dgraph

## Features
Expand All @@ -24,7 +26,7 @@ cache in [Dgraph][].

## Status

Ristretto is usable but still under active development. We expect it to be production ready in the near future.
Ristretto is production-ready. See [Projects using Ristretto](#projects-using-ristretto).

## Table of Contents

Expand All @@ -48,6 +50,7 @@ Ristretto is usable but still under active development. We expect it to be produ
* [Mixed](#Mixed)
* [Read](#Read)
* [Write](#Write)
* [Projects using Ristretto](#projects-using-ristretto)
* [FAQ](#FAQ)

## Usage
Expand All @@ -69,7 +72,7 @@ func main() {
cache.Set("key", "value", 1)

// wait for value to pass through buffers
time.Sleep(10 * time.Millisecond)
cache.Wait()

value, found := cache.Get("key")
if !found {
Expand Down Expand Up @@ -196,6 +199,15 @@ of RAM.
<img src="https://raw.githubusercontent.com/dgraph-io/ristretto/master/benchmarks/Throughput%20-%20Write%20(Zipfian).svg">
</p>

## Projects Using Ristretto

Below is a list of known projects that use Ristretto:

- [Badger](https://github.com/dgraph-io/badger) - Embeddable key-value DB in Go
- [Dgraph](https://github.com/dgraph-io/dgraph) - Horizontally scalable and distributed GraphQL database with a graph backend
- [Vitess](https://github.com/vitessio/vitess) - Database clustering system for horizontal scaling of MySQL
- [SpiceDB](https://github.com/authzed/spicedb) - Horizontally scalable permissions database

## FAQ

### How are you achieving this performance? What shortcuts are you taking?
Expand Down
Loading