Comments (8)
I used ristretto in our company's project, and I really need help!
from ristretto.
Can the author help give the correct code example(use 200M memory)? My English is very poor, thank you very much!
from ristretto.
package main
import (
"fmt"
"math/rand"
"strconv"
"sync"
"time"
"github.com/dgraph-io/ristretto"
)
const (
maxLoop = 1e8
maxCnt = 1e7
)
func main() {
cost := int64(100 * 1024 * 1024)
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: cost / 8,
MaxCost: cost / 88, // key+value size
BufferItems: 64,
})
if err != nil {
panic(err)
}
key := `def48b5abb6388d3cbbb18e550f47b4cYB6eRI3cK1VN2qCEHp8kvuMuH20dq10cYDcG2e
var wg sync.WaitGroup
for i := 0; i < maxLoop/maxCnt; i++ {
wg.Add(1)
go func() {
now := time.Now()
for i := 0; i < maxCnt; i++ {
val := strconv.Itoa(rand.Intn(maxCnt))
cache.Set(key+val, val, 1)
}
fmt.Println(time.Since(now).Seconds())
wg.Done()
}()
}
wg.Wait()
cnt := 0
now := time.Now()
for i := 0; i < maxCnt; i++ {
_, found := cache.Get(key + strconv.Itoa(i))
if found {
cnt++
}
}
fmt.Println(time.Since(now).Seconds())
fmt.Println(cnt)
time.Sleep(10 * 60 * time.Second)
}
write
196.145246674
196.594516091
198.114088657
198.93801043
201.966241441
202.236675922
204.914710305
204.955456302
205.115802574
205.308419901
read
24.981067788
count
1191525
from ristretto.
package main
import (
"fmt"
"math/rand"
"strconv"
"sync"
"time"
"github.com/coocood/freecache"
)
const (
maxLoop = 1e8
maxCnt = 1e7
)
func main() {
cacheSize := 100 * 1024 * 1024 // 1GB
cache := freecache.NewCache(cacheSize)
expire := 60 * 60 // expire in 60 seconds
key := `def48b5abb6388d3cbbb18e550f47b4cYB6eRI3cK1VN2qCEHp8kvuMuH20dq10cYDcG2e
var wg sync.WaitGroup
for i := 0; i < maxLoop/maxCnt; i++ {
wg.Add(1)
go func() {
now := time.Now()
for i := 0; i < maxCnt; i++ {
val := strconv.Itoa(rand.Intn(maxCnt))
cache.Set([]byte(key+val), []byte(val), expire)
}
fmt.Println(time.Since(now).Seconds())
wg.Done()
}()
}
wg.Wait()
cnt := 0
now := time.Now()
for i := 0; i < maxCnt; i++ {
_, err := cache.Get([]byte(key + strconv.Itoa(i)))
if err == nil {
cnt++
}
}
fmt.Println(time.Since(now).Seconds())
fmt.Println("entry count ", cnt, cache.EntryCount())
time.Sleep(10 * 60 * time.Second)
}
write
143.327503682
144.094319665
144.148188694
145.014152054
145.317289531
146.429781022
146.803659841
146.842320393
146.899385914
146.907347694
read
9.807717003
count
entry count 868063 868063
from ristretto.
memory contrash
freecache: 300M // keep 300M
ristretto: 1.7G // up to 1.7G, time.Sleep(10 * 60 * time.Second) -> 660M
from ristretto.
Hi.
Sorry for not answering your question more promptly. We have been at work trying to release Dgraph 2.0.0.
I am not really sure why the differences in memory exist but I suspect you might have run into the bug described in #107.
The key in your examples are very big so if they escape to the heap they will use a lot more memory. For now, I suggest using smaller keys (uint64
for example).
from ristretto.
Re-open the issue to test github-issue porting task.
from ristretto.
Github issues have been deprecated.
This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.
from ristretto.
Related Issues (20)
- [QUESTION]: Differentiate between TTL and cost based eviction
- [FEATURE]: Support for Type Parameters, aka, generics HOT 1
- [BUG]: ristretto used about 2 x MaxCost memory?? HOT 5
- benchmark about gc or plan to reduce gc HOT 1
- [BUG]: Expiration map grows without limit HOT 6
- [QUESTION]: Why did you choose ristretto as the project name ? HOT 2
- [FEATURE]: Loading or Compute If key is not present
- How many bits tinyLFU uses to count access frequency? HOT 1
- [QUESTION]: Ristretto hit ratio benchmark result HOT 2
- [BUG]: <sync.Pool GC>
- [QUESTION]: Too high missed rate?
- [FEATURE]: Jemalloc 5.3.0
- [FEATURE]: use system jemalloc
- [Non-hashed key values in Item]: onEvict should send the non hashed key values HOT 1
- [BUG]: compilation reports asm error when -buildmode=plugin
- [QUESTION]: Is there any way to implement an expired map counter with ristretto?
- [QUESTION]: How can I pre warm the cache ?
- [QUESTION]: When get v.0.1.2 tag and it's release note?
- [QUESTION]: Why is Ristretto so slow and has such a small hit ratio?
- Update projects using ristretto
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ristretto.