Skip to content

feat(job): implement Redis Set storage for SyncPeersJob to avoid big key issues #4654#4668

Closed
liyi1013 wants to merge 1 commit into
dragonflyoss:mainfrom
liyi1013:feat_redis_bigkeys_2
Closed

feat(job): implement Redis Set storage for SyncPeersJob to avoid big key issues #4654#4668
liyi1013 wants to merge 1 commit into
dragonflyoss:mainfrom
liyi1013:feat_redis_bigkeys_2

Conversation

@liyi1013

Copy link
Copy Markdown

Description

The Dragonfly syncPeer job has the potential to cause a Redis Big Key Problem (value > 100k)when the number of peer nodes is excessive, which poses a risk of degrading Redis performance.

This PR updates the logic to store SyncPeersJob results in a Redis set instead of storing them as a single string.

Related Issue

#4379

Motivation and Context

Instead of serializing the entire result into a large JSON string (which could lead to Redis big key issues), this PR serializes individual host objects and stores them into a Redis Set. The task then returns the key of this Set. During retrieval, the results are fetched directly from Redis via this key.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

…is_bigkey_s

Signed-off-by: LiYi <liyi1013@foxmail.com>

Solve redis big key problem
Comment thread internal/job/job.go

// save results to redis set
for _, val := range data {
if err := t.rdb.SAdd(ctx, key, val).Err(); err != nil {

@CooooolFrog CooooolFrog Mar 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When the number of peers becomes excessively large, wouldn't this approach actually place a greater strain on redis?

With 100,000 Peers, this implies that the redis.sAdd() method must be invoked 100,000 times. Although this eliminates the issue of a single Key holding an excessively large volume of data, it introduces a new problem: executing redis.sAdd() 100,000 times incurs significant overhead—potentially resulting in a situation even worse than the original one.

Regardless of how redis.SAdd() is invoked, it alters only the write method, not the resulting data structure. Whether you write 100,000 entries in a single operation or perform 100,000 separate writes of one entry each, the outcome remains the same: a single Set containing 100,000 members.

In a separate PR(#4654), the implementation utilizes sharding to limit the number of Peers associated with any single Key. This method resolves the issue of excessive data storage under a single Key without incurring the overhead of repeated redis.sAdd() calls. I believe this implementation approach is superior; what are your thoughts?

To summarize, I think the correct approach is to attempt to shard the data using different keys, rather than writing data to the same key in small, frequent increments.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity.

@github-actions github-actions Bot added the Stale label May 31, 2026
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants