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

Snapshot flushes to disk async from event channel #524

Merged
merged 1 commit into from
Aug 8, 2018
Merged

Conversation

armon
Copy link
Member

@armon armon commented Aug 8, 2018

Previously the Snapshotter would synchronously consume events and write out to the snapshot file. A slow disk could cause a slowdown of event processing, putting back pressure on Serf and Memberlist.

This PR changes Snapshotter to copy events to the output channel and an internal stream channel immediately, without blocking. The internal stream channel is consumed to write to disk, so that the snapshot is written async from event processing. This prevents a slow disk from delaying events.

flushEvent(e)
default:
return
}
Copy link
Member

Choose a reason for hiding this comment

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

nitpick you could just replace this whole loop with:

for e := range s.inCh {
  flushEvent(e)
}

but no big deal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we don't close the inCh, won't this block?

Copy link
Member

Choose a reason for hiding this comment

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

Heh yep, good point.

@banks banks merged commit 9f65f2f into master Aug 8, 2018
@banks banks deleted the f-async-flush branch August 8, 2018 20:18
mkeeler pushed a commit to hashicorp/consul that referenced this pull request Aug 9, 2018
This includes fixes that improve gossip scalability on very large (> 10k node) clusters.

The Serf changes:
 - take snapshot disk IO out of the critical path for handling messages hashicorp/serf#524
 - make snapshot compaction much less aggressive - the old fixed threshold caused snapshots to be constantly compacted (synchronously with request handling) on clusters larger than about 2000 nodes! hashicorp/serf#525

Memberlist changes:
 - prioritize handling alive messages over suspect/dead to improve stability, and handle queue in LIFO order to avoid acting on info that 's already stale in the queue by the time we handle it. hashicorp/memberlist#159
 - limit the number of concurrent pushPull requests being handled at once to 128. In one test scenario with 10s of thousands of servers we saw channel and lock blocking cause over 3000 pushPulls at once which ballooned the memory of the server because each push pull contained a de-serialised list of all known 10k+ nodes and their tags for a total of about 60 million objects and 7GB of memory stuck. While the rest of the fixes here should prevent the same root cause from blocking in the same way, this prevents any other bug or source of contention from allowing pushPull messages to stack up and eat resources. hashicorp/memberlist#158
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