Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve memory performance #195

Merged
merged 3 commits into from
Sep 28, 2020
Merged

Improve memory performance #195

merged 3 commits into from
Sep 28, 2020

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Sep 22, 2020

  • Use an int64 instead of a time.Time struct to represent the time.
  • By default, include the cost of the storeItem in the cost calculation.

Related to DGRAPH-1378


This change is Reviewable

@CLAassistant
Copy link

CLAassistant commented Sep 22, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @anurags92 and @karlmcguire)

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

This is good to go.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @anurags92 and @karlmcguire)

@martinmr martinmr merged commit 5f615bf into master Sep 28, 2020
@martinmr martinmr deleted the martinmr/memopt branch September 28, 2020 22:37
@varun06
Copy link

varun06 commented Oct 12, 2020

@martinmr I have a test where I add a value to cache with TTL and then check for that value after TTL passed(say one second), that test is failing after this change(works fine with v0.0.3 ofc). I had to increase my wait time to make that test pass. I don't see any change that would do that in quick pass over code, but it would be a good idea to check SetWithTTL tests after this change.

@varun06
Copy link

varun06 commented Oct 12, 2020

Alright, so did some testing with couple sha's around this change, and this change definitely has some kind of regression with TTL.

@jarifibrahim
Copy link
Contributor

hey @varun06 , can you share your test? Maybe send a PR to add it to ristretto? We can look at the failing test if this change has caused it.

@varun06
Copy link

varun06 commented Nov 7, 2020

sure @jarifibrahim
going to replicate it this weekend and if it fails again, will send you the test...

@varun06
Copy link

varun06 commented Nov 9, 2020

@jarifibrahim This is the test that's failing

func TestRisPutGetOnExpiredItem(t *testing.T) {
	c, err := NewCache(10, 100, 1, false)
	if err != nil {
		t.Fatalf("cache creation error: %v", err)
	}

	value := []byte("my cache value")
	key := getCacheKey(t)
	keyStr := key.String()
	defer key.Close()

	// put
	err = c.Put(&key, bytes.NewBuffer(value), time.Now().Add(1*time.Second))
	if err != nil {
		t.Fatalf("key %s was not put", keyStr)
	}

	//wait for values to settle
	time.Sleep(10 * time.Millisecond)

	// get
	_, _, stat, err := c.Get(&key)
	if err != nil {
		t.Fatalf("key %s was not get", keyStr)
	}

	if stat != cutl.StatusPresent {
		t.Errorf("key %s expected to be 'present': got %q.", keyStr, stat)
	}

	// Wait for 1 second, item will expire
	time.Sleep(1 * time.Second)

	// verify item is missing
	_, _, stat, err = c.Get(&key)
	if err != nil {
		t.Fatalf("key %s was not get", keyStr)
	}

	if stat != cutl.StatusMissing {
		t.Errorf("key %s expected to be 'missing': got %s", keyStr, stat)
	}
}

=== RUN   TestRisPutGetOnExpiredItem
    ristretto_test.go:179: key 0#0#0#example.com/ expected to be 'missing': got PRESENT
--- FAIL: TestRisPutGetOnExpiredItem (1.01s)

@varun06
Copy link

varun06 commented Nov 9, 2020

so it seems that there is a regression when we use SetWithTTL.

@jarifibrahim
Copy link
Contributor

Looks like I missed the replies. @varun06 the issue has been resolved now via #277 .
Apologies for the late reply.

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

Successfully merging this pull request may close these issues.

5 participants