GithubHelp home page GithubHelp logo

elastic / go-freelru Goto Github PK

View Code? Open in Web Editor NEW
112.0 4.0 9.0 72 KB

GC-less, fast and generic LRU hashmap library for Go

License: Apache License 2.0

Go 85.62% Assembly 11.77% Makefile 0.19% Python 2.41%
cache data-structures go golang library lru gc-less

go-freelru's Issues

what could be causing this panic?

We are reaching a panic in setHead (excerpt below) in one of our apps.

panic({0x18b5fc0?, 0x400301d47c?})
    runtime/panic.go:770 +0x124
github.com/elastic/go-freelru.(*LRU[...]).setHead(...)\n\tgithub.com/elastic/[email protected]/lru.go:178
github.com/elastic/go-freelru.(*LRU[...]).get(0x173feb4, 0x4606100?, {0x40000b65a0?, 0x4005e1ef00?})
    github.com/elastic/[email protected]/lru.go:423 +0x214
github.com/elastic/go-freelru.(*LRU[...]).Get(0x211f040, {0x40000b65a0, 0xa0})
    github.com/elastic/[email protected]/lru.go:416 +0x58

I was wondering which conditions could be having us reach that point, and why should the library panic there?

Right now this is causing a problem in our service because we wrapped the call to freelru.Get in a mutex lock/unlock block.
After the panic happens, we don't release the lock anymore.

Request a shard version of LRU implementation.

This LRU implementation is very impressive, and I believe its performance should be one of the top, thanks for this brilliant job!
But we really need a sharded version instead of synced version to perform well in a high parallelism.

For example, a "shardedlru.go" like

type ShardedLRU[K comparable, V any] struct {
	mu  []sync.RWMutex
	lru []*LRU[K, V]
}

Background:
I happen to be currently implementing a simple lru cache as well, and would like to know how its performance compares to popular libraries. Here is my results on

const (
	keysize     = 16
	cachesize   = 16384
	parallelism = 1000
)
goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz
BenchmarkCloudflareGet
BenchmarkCloudflareGet-8   	100000000	        60.48 ns/op	      16 B/op	       1 allocs/op
BenchmarkElasticGet
BenchmarkElasticGet-8      	15093165	       424.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkHashicorpGet
BenchmarkHashicorpGet-8    	27390493	       349.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkPhusluGet
BenchmarkPhusluGet-8       	199958748	        30.45 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	command-line-arguments	32.350s

Obviously freelru (and hashicorp) does not perform as well as it should (I think it should be top-notch) due to the use of a single lock.
Please refer to https://github.com/phuslu/lru?tab=readme-ov-file#benchmarks for the code, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.