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

Cache: support redis cache backend #4888

Merged
merged 7 commits into from
Dec 7, 2021

Conversation

hanjm
Copy link
Member

@hanjm hanjm commented Nov 22, 2021

Hi, I am attempt to add redis cache support, like cortex does.
First. i will make it a draft PR.

Signed-off-by: Jimmie Han hanjinming@outlook.com

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

  1. add redis support for bucket-cache/index-cache/query-frontend

Verification

  1. unit test.
  2. continning test in production deployment.

@hanjm hanjm marked this pull request as draft November 22, 2021 11:06
Copy link
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

I haven't checked the code yet but have you seen the implementation on Cortex side https://github.com/cortexproject/cortex/blob/34bb142b129bd781539001fb1629cf2f3ed54b82/pkg/chunk/cache/redis_cache.go? Maybe there is an opportunity to share some code here?

@hanjm
Copy link
Member Author

hanjm commented Nov 24, 2021

I haven't checked the code yet but have you seen the implementation on Cortex side https://github.com/cortexproject/cortex/blob/34bb142b129bd781539001fb1629cf2f3ed54b82/pkg/chunk/cache/redis_cache.go? Maybe there is an opportunity to share some code here?

Thank you your review, I see the redis code in cortex not have a expire ttl in store function,it use a fixed ttl. so it can not reuse for our interface https://github.com/thanos-io/thanos/blob/main/pkg/cache/cache.go#L16. the redis support code is not very complex,i think write it again is seems not matter. (:

@hanjm hanjm force-pushed the feature/store-redis-cache branch 4 times, most recently from 0887806 to c6dccaa Compare November 26, 2021 02:20
@hanjm
Copy link
Member Author

hanjm commented Nov 26, 2021

I found the redis client invoke mget has too many keys. let me implement split it to batch.

@hanjm hanjm force-pushed the feature/store-redis-cache branch 3 times, most recently from 1eddee6 to 801384f Compare November 28, 2021 14:36
@hanjm
Copy link
Member Author

hanjm commented Nov 28, 2021

🚀 Ready to review. I am also deploymented it to production to continuing verify. it works well than memcached in my scene(no i/o timeout, no mem leak).

@hanjm hanjm marked this pull request as ready for review November 28, 2021 14:57
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
make linter happy

Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
@hanjm hanjm force-pushed the feature/store-redis-cache branch 2 times, most recently from 0a590f7 to f0a9278 Compare December 3, 2021 08:30
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Great job! Just comment to fix, but not a blocker, we can fix later. LGTM! 💪🏽

pkg/queryfrontend/cache.go Show resolved Hide resolved
@bwplotka
Copy link
Member

bwplotka commented Dec 7, 2021

Retried e2e test, let's see if that's a flakiness.

@bwplotka bwplotka enabled auto-merge (squash) December 7, 2021 16:17
@bwplotka bwplotka merged commit 397fcb1 into thanos-io:main Dec 7, 2021
@hanjm
Copy link
Member Author

hanjm commented Dec 8, 2021

Thank you🚀, I will fix it later.

@hanjm hanjm deleted the feature/store-redis-cache branch December 8, 2021 11:13
@hanjm hanjm mentioned this pull request Dec 8, 2021
2 tasks
}
duration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Name: "thanos_redis_operation_duration_seconds",
Help: "Duration of operations against memcached.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: should be Duration of operations against redis.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me fix it.

jordy1024 pushed a commit to jordy1024/thanos that referenced this pull request Dec 12, 2021
* Cache: support redis cache backend

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* Cache: add get gate

make linter happy

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* add concurrent config  control

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* add redis cache doc

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* use doWithBatch to optmize concurrent batch code.

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* support db select

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* fix query-frontend cache config

Signed-off-by: Jimmie Han <hanjinming@outlook.com>
jordy1024 pushed a commit to jordy1024/thanos that referenced this pull request Dec 12, 2021
* Cache: support redis cache backend

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* Cache: add get gate

make linter happy

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* add concurrent config  control

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* add redis cache doc

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* use doWithBatch to optmize concurrent batch code.

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* support db select

Signed-off-by: Jimmie Han <hanjinming@outlook.com>

* fix query-frontend cache config

Signed-off-by: Jimmie Han <hanjinming@outlook.com>
Signed-off-by: wenmaoba <wenmaoba@tencent.com>
@pgold30
Copy link

pgold30 commented Feb 2, 2022

Love to see this, do you have a performance comparison with / without this to see if its better ? @hanjm specially the comparison you did vs "memcached in my scene(no i/o timeout, no mem leak)." , would be great if you have some numbers :)

@fagossa
Copy link

fagossa commented Feb 4, 2022

Hello,
any idea when this is going to be released?
thanks a lot for the great job 👍

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.

6 participants