Coder Social home page Coder Social logo

Optimizing for concurrency about lru-rs HOT 7 OPEN

rohitjoshi avatar rohitjoshi commented on June 25, 2024
Optimizing for concurrency

from lru-rs.

Comments (7)

jeromefroe avatar jeromefroe commented on June 25, 2024 1

Great, thanks for the references! Hopefully benchmarking and profiling will reveal some quick wins, anything more extensive might be better left for a new crate which implements the same interface.

from lru-rs.

jeromefroe avatar jeromefroe commented on June 25, 2024

This is a great question! Admittedly, when I first started working on this project, I intended it to be a learning experience so I didn't focus on performance very much. It would definitely be interesting to go back and revisit different parts of the cache now though. Of course, as the saying goes, "If you can't measure it, you can't improve it". So I'll probably start by writing some benchmarks which can provide a baseline against which any changes can be compared.

from lru-rs.

rohitjoshi avatar rohitjoshi commented on June 25, 2024

👍. I used xxhash which gives slightly better performance.

from lru-rs.

rohitjoshi avatar rohitjoshi commented on June 25, 2024

RocksDB's Shared cache which sharded into multiple LRU cache is faster.
I did implement sharding of 128 LRU cache but still, RocksDB's performance is better. Might want to use as a reference.
https://github.com/facebook/rocksdb/blob/master/cache/lru_cache.cc and https://github.com/facebook/rocksdb/blob/master/cache/sharded_cache.cc

from lru-rs.

Firstyear avatar Firstyear commented on June 25, 2024

@rohitjoshi You may also find this useful https://crates.io/crates/concread this has a concurrently readable / transactional cache implementation.

from lru-rs.

rohitjoshi avatar rohitjoshi commented on June 25, 2024

@Firstyear Thanks for sharing. Earlier I saw evmap as well but both of these don't support LRU algorithm. In my use-case, existing keys are never updated and the read vs write ratio is 9-1 so trying to figure out an optimized lookup. For now, I am splitting 200M LRU capacity into 2048 shards (LRU instances) to reduce the lock.

from lru-rs.

Firstyear avatar Firstyear commented on June 25, 2024

@rohitjoshi If your keys are never updated, and you are mainly read to write, then you have ever more reason to look at the arcache. This design has "no" locking, allows full parallel lookups between all readers, and when you have a "cache miss" any reader can include content to the cache without blocking existing readers. For bonus, it also support SIMD for parallel key lookups via a feature + nightly rust. Additionally, ARC as a cache replacement strategy is far more effective than LRU :)

https://github.com/kanidm/concread/blob/master/CACHE.md
https://docs.rs/concread/0.2.6/concread/arcache/index.html

Feel free to email me directly (rather that us annoying @jeromefroe) - it can be found on my github profile.

from lru-rs.

Related Issues (20)

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.