Skip to content

Create basic contentcache test#16

Closed
toshinari123 wants to merge 1 commit intooursky:mainfrom
toshinari123:test-contentcache
Closed

Create basic contentcache test#16
toshinari123 wants to merge 1 commit intooursky:mainfrom
toshinari123:test-contentcache

Conversation

@toshinari123
Copy link
Copy Markdown
Contributor

No description provided.

@toshinari123 toshinari123 marked this pull request as draft January 24, 2024 10:15
Copy link
Copy Markdown
Collaborator

@kiootic kiootic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please combine this PR with #15, we would add a feature along with its test in one PR.

)

func TestGetContent(t *testing.T) {
cc, err := NewContentCache(128, true) //for some reason Set fails if size <= 60
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Can we investigate the reason?

size := contentCacheSize
cache, err := ristretto.NewCache(&ristretto.Config{
//NumCounters is 10 times estimated max number of items in cache, as suggested in https://pkg.go.dev/github.com/dgraph-io/ristretto@v0.1.1#Config
NumCounters: 1e7,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is calculated from number of items, not size of items. I don't think there would be 1000000 files in the cache.


ce := ContentCacheCell{
id: id,
Data: bytes.NewBuffer(bytes.Trim(b, string([]byte{0x0}))),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need trim 0 bytes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because b is initialized with max cache size, there are 0 bytes after reading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be problematic:

  • Every time we load a file, no matter how large/small it is, we will allocate the max cached file size (~10MB), which makes memory cosumption unnecessarily high.
  • The file can ends with 0 bytes, and removing them would be inappropiate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants