在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dgraph-io/ristretto开源软件地址:https://github.com/dgraph-io/ristretto开源编程语言:Go 98.6%开源软件介绍:RistrettoRistretto 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 for reporting issues about this repository. Features
StatusRistretto is production-ready. See Projects using Ristretto. Table of ContentsUsageExamplefunc main() {
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1e7, // number of keys to track frequency of (10M).
MaxCost: 1 << 30, // maximum cost of cache (1GB).
BufferItems: 64, // number of keys per Get buffer.
})
if err != nil {
panic(err)
}
// set a value with a cost of 1
cache.Set("key", "value", 1)
// wait for value to pass through buffers
cache.Wait()
value, found := cache.Get("key")
if !found {
panic("missing value")
}
fmt.Println(value)
cache.Del("key")
} ConfigThe NumCounters NumCounters is the number of 4-bit access counters to keep for admission and eviction. We've seen good performance in setting this to 10x the number of items you expect to keep in the cache when full. For example, if you expect each item to have a cost of 1 and MaxCost is 100, set NumCounters to 1,000. Or, if you use variable cost values but expect the cache to hold around 10,000 items when full, set NumCounters to 100,000. The important thing is the number of unique items in the full cache, not necessarily the MaxCost value. MaxCost MaxCost is how eviction decisions are made. For example, if MaxCost is 100 and a new item with a cost of 1 increases total cache cost to 101, 1 item will be evicted. MaxCost can also be used to denote the max size in bytes. For example, if MaxCost is 1,000,000 (1MB) and the cache is full with 1,000 1KB items, a new item (that's accepted) would cause 5 1KB items to be evicted. MaxCost could be anything as long as it matches how you're using the cost values when calling Set. BufferItems BufferItems is the size of the Get buffers. The best value we've found for this is 64. If for some reason you see Get performance decreasing with lots of contention (you shouldn't), try increasing this value in increments of 64. This is a fine-tuning mechanism and you probably won't have to touch this. Metrics Metrics is true when you want real-time logging of a variety of stats. The reason this is a Config flag is because there's a 10% throughput performance overhead. OnEvict OnEvict is called for every eviction. KeyToHash KeyToHash is the hashing algorithm used for every key. If this is nil, Ristretto has a variety of defaults depending on the underlying interface type. Note that if you want 128bit hashes you should use the full Cost Cost is an optional function you can pass to the Config in order to evaluate item cost at runtime, and only for the Set calls that aren't dropped (this is useful if calculating item cost is particularly expensive and you don't want to waste time on items that will be dropped anyways). To signal to Ristretto that you'd like to use this Cost function:
BenchmarksThe benchmarks can be found in https://github.com/dgraph-io/benchmarks/tree/master/cachebench/ristretto. Hit RatiosSearchThis trace is described as "disk read accesses initiated by a large commercial search engine in response to various web search requests." DatabaseThis trace is described as "a database server running at a commercial site running an ERP application on top of a commercial database." LoopingThis trace demonstrates a looping access pattern. CODASYLThis trace is described as "references to a CODASYL database for a one hour period." ThroughputAll throughput benchmarks were ran on an Intel Core i7-8700K (3.7GHz) with 16gb of RAM. MixedReadWriteProjects Using RistrettoBelow is a list of known projects that use Ristretto:
FAQHow are you achieving this performance? What shortcuts are you taking?We go into detail in the Ristretto blog post, but in short: our throughput performance can be attributed to a mix of batching and eventual consistency. Our hit ratio performance is mostly due to an excellent admission policy and SampledLFU eviction policy. As for "shortcuts," the only thing Ristretto does that could be construed as one is dropping some Set calls. That means a Set call for a new item (updates are guaranteed) isn't guaranteed to make it into the cache. The new item could be dropped at two points: when passing through the Set buffer or when passing through the admission policy. However, this doesn't affect hit ratios much at all as we expect the most popular items to be Set multiple times and eventually make it in the cache. Is Ristretto distributed?No, it's just like any other Go library that you can import into your project and use in a single process. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论